我是靠谱客的博主 殷勤灯泡,这篇文章主要介绍int.Class和integer.class不是一回事,现在分享给大家,希望可以做个参考。

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不是一回事的全部内容,更多相关int内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部