在 java 反射中发送到 getDeclaredMethod(String, Class[]) 的参数类型
我在这样的类中有一个方法:
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
的类对象???
我已经知道 ((List
的方式,但应该有更直接的方式...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所需要的只是以下
运行时不需要泛型类型。
All you need is the following
The generic type is not required at runtime.