您的位置:首页 > 其它

int.Class和integer.class不是一回事

2011-09-28 14:11 232 查看
 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不是一回事情



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息