如何将getMethod()与原始类型一起使用? [英] How to use getMethod() with primitive types?
本文介绍了如何将getMethod()与原始类型一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是课程:
class Foo {
public void bar(int a, Object b) {
}
}
现在,我正在尝试从类中反射"此方法:
Now I'm trying to get "reflect" this method from the class:
Class c = Foo.class;
Class[] types = { ... }; // what should be here?
Method m = c.getMethod("bar", types);
推荐答案
只有一个 int.class
.
Class[] types = { int.class, Object.class };
替代方法是 Integer.类型
.
An alternative is Integer.TYPE
.
Class[] types = { Integer.TYPE, Object.class };
其他基元也是如此.
这篇关于如何将getMethod()与原始类型一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文