I have this interface:
public interface EventHandler<T extends Event> {
void handle(T event);
}
And this class implements this:
public class MyEventHandler implements EventHandler<MyEvent> {
@Override
public void handle(MyEvent event) {
}
}
Considering:
Class myEventHandlerClass = getClazz();
In this class parameter T MyEvent, this is a specific implementation Event. How can this be obtained by reflection?
I need something like this:
Class myEventHandlerClass = getClazz();
Method handleMethod = myEventhandlerClass.getDeclaredMethod("handle");
Class<?>[] params = method.getParameterTypes();
Class<?> eventConcreteType = params[0];
But myEventhandlerClass.getDeclaredMethod("handle");throws NoSuchMethodException, since I did not specify the type of parameter, because I just know that this is a specific implementation Event, but I do not know which one.
source
share