Java. Checking the type of an Anonymous Implementation of an Interface -


i'm working wicket, building set decoupled components. while using event driven mechanism let components communicate, i'm keeping set in class "genericcomponent". basic idea send event, "someevent.class" payload extends igenericevent. in onevent method genericcomponent class, go through events added set. if class matches payload, event should executed.

now code:

genericcomponent

public class  genericcomponent<t> extends genericpanel<t> { //...     protected set<igenericevent>eventset = new hashset<igenericevent>();  //...      public void addevent(final igenericevent event)     {         boolean result = eventset.add(event);         if (!result)         {              throw new illegalargumentexception("event added ...");         }     }      @override     public void onevent(final ievent<?> event)     {         (igenericevent e : eventset)         {              if (e.getclass().equals(event.getpayload()))             {                  e.action(this.getcontainer());             }          }         update();     }  } 

igenericevent

public interface  igenericevent {      public void action(final webmarkupcontainer container);  } 

hideevent

public class hide implements igenericevent, serializable {     private static final long serialversionuid = 1l;      @override     public void action(webmarkupcontainer container)     {         container.setvisible(false);      }  } 

the problem:

if define onaction event implementing igenericevent described before, ok.

the problem when in page self, anonymous implementation of interface. then, class pagesomething$1,2,3.

errormessage.add(new hide() {     private static final long serialversionuid = 1l;      @override     public void onaction(component component)     {         system.out.println("here");     }   }); 

i have tried isasignablefrom , class.isintance, indeed makes sense; class of anonymous implementation pagesomething. isasignablefrom or isinstance wont apply.

i refuse believe should use generics actual class/interface being used.

abstractevent<hide>.

i hope guys understand problem.

thanks in advance.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -