4
我有像这样一类的方法:参数类型
public static void postEvents(List<RuleEvent> eventList) {
for(RuleEvent event:eventList)
if(canProcess(event))
findListenerAndPost(event);
}
,我想使用反射像这样来访问它:
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);
这样,我怎么得到List<RuleEvent>
类对象????
我已经知道的((List<RuleEvent>) new ArrayList<RuleEvent>()).getClass()
的方式,但应该有一个更直接的方式......
工作正常,我。你有错误吗?由于类型擦除,在运行时没有'List'。 –
2012-01-02 14:09:55
我只是找不到方法。它'cls'权类当属无效 – MozenRath 2012-01-02 14:10:46
是?空值?!如果方法不存在,你应该得到一个'NoSuchMethodException'。 – 2012-01-02 14:11:40