public class Test {
public void test(int x){
System.out.println(x);
}
public static void main(String[] args) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
//error: Exception in thread "main" java.lang.NoSuchMethodException: com.webex.learning.Test.test(java.lang.Integer)
/* Class<?> forName = Class.forName("com.webex.learning.Test");
Method method = forName.getDeclaredMethod("test", Integer.class);
method.invoke(forName.newInstance(), 10);*/
Class<?> forName = Class.forName("com.webex.learning.Test");
Method method = forName.getDeclaredMethod("test", int.class);
method.invoke(forName.newInstance(), 10);
}
}
测试了下:
说明(1)int.Class=Integer.TYPE,但是和integer.class不是一回事情
int.Class和integer.class不是一回事
最新推荐文章于 2024-05-21 15:32:45 发布