i have a method in a class like this:
public static void postEvents(List<RuleEvent> eventList) {
for(RuleEvent event:eventList)
if(canProcess(event))
findListenerAndPost(event);
}
and i want to access it using reflection like this:
Class partypes[] = new Class[1];
partypes[0] = List.class; //does not find the method as it is of List<RuleEvent>
postMethod = cls.getMethod("postEvents", partypes);
so, how do I get the class object of List<RuleEvent>????
I already know the way of ((List<RuleEvent>) new ArrayList<RuleEvent>()).getClass() but there should be a more direct way...
List<RuleEvent>at runtime.clsthe right class? Null?! You should get aNoSuchMethodExceptionif the method doesn't exist.new ArrayList<RuleEvent>().getClass()works either - first of all, since it returns an ArrayList.class rather than List.class, and second, because of type erasure, it still returns a raw ArrayList.class object.