请问各位高手
JAVA反射机制中
Class.getDeclaredMethod(String name, Class... parameterTypes)中的形参
Class... parameterTypes 怎么理解?如果可以的话请问下怎么通过反射使用Test类中的show()方法
class Test {
public show() {
System.out.println("Hello World!");
}
}
谢谢!
JAVA反射机制中
Class.getDeclaredMethod(String name, Class... parameterTypes)中的形参
Class... parameterTypes 怎么理解?如果可以的话请问下怎么通过反射使用Test类中的show()方法
class Test {
public show() {
System.out.println("Hello World!");
}
}
谢谢!
name - 方法名
parameterTypes - 参数数组该类与指定名和参数相匹配的方法的 Method 对象 Class c = Class.forName("Test");
Object o = c.newInstance();
Method[] ms=c.getDeclaredMethods();
ms[0].ivoke(o,null);
Object o = c.newInstance();
Method ms=c.getDeclaredMethod("show",null);
ms.ivoke(o,null);这样应该也可以