这是类(class):
class Foo {
public void bar(int a, Object b) {
}
}
现在我正试图从类中“反射(reflect)”这个方法:
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.TYPE
.
Class[] types = { Integer.TYPE, Object.class };
这同样适用于其他原语。
关于java - 如何将 getMethod() 与原始类型一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5032833/