Using Java Generics with Enums -


Update: Thanks for all people who help - the answer to who I was More complex code is not being ignored and I did not know about Java 5 code type types.

Original post:

I am playing with something this morning. Although I know that I can deal with this whole problem differently, I have to find out that the way I was hoping it is not working, I feel mad Has been doing. After spending some time in reading around this, I understand that I am not close to understanding, so I have to present it as a question to see if I am just stupid or if really That's what I'm not coming here.

I created a custom event hierarchy such as:

  Public abstract class abstract essive {Private S src; Private T. ID; Public Abbeycher Event (SKR, T ID) {this.src = src; This.id = ID; } Public S getSource () {Return src; } Public T getId () {Return ID; }}  

With such a concrete implementation:

  Public Class Expands MyEvent AbstractEvent < String, MyEvent.Type & gt; {Public Enum Type {SELECTED, SELECTION_CLEARED}; Public MyEvent (string source, type T) {super (src, t); }}  

And then I will create an event such as:

  fireEvent (new MyEvent ("MyClass.myMethod", MyEvent.Type.SELECTED));  

Where my firewire is defined:

  Secure void fireEvent (MyEvent event) {for (EventListener l: getListeners ()) {switch ( Event. GetId ()) {Case selected: L. Selected (event); break; Case SELECTION_CLEARED: l.unselect (event); break; }}}  

So I thought it would be very straightforward, but it came to know that call to event.getId () will tell in the compiler that I can not switch to Enums, only convertible It is possible to add the following method to MyEvent: difference value or ANIM constant

  public type getId () {return super.getId (); }  

Once I do this, everything works properly as I expected I am not interested in finding a workaround for this matter (because I clearly I am interested in people with any insights because this does not work because I hope it is right from the bat. getId () into your own class as the Java can handle in run-time.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -