基本类型 和 Wrapper类类型的区别. 1.为什么Java语言为提供两套数据类型(基本类型和Wrapper类类型)?2.在使用基本数据类型的位置能否直接用与其对应的Wrapper类替换? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个基本的, 一个是抽象的, 在必须用抽象的时候,比如所以 Collection , Map 之类的, 就要用 Wrapper,如果是在 Class 中用 Reflection 时需要 基本类型的参数据, 用 Wrapper 就行, 会自动处理转换,如果你明确指定要找一个基本类型为参数的方法 ,可以用 Integer.TYPE 这种方式, 或者直接用 int.class , 因为 Class 对象有个 isPrimitive () 方法, 所以 new Integer().getClass() 和 int.class 得到的是不同的东西 , JVM 会区分的.测试一下:Class c1 = new Integer(5).getClass();Class c2 = int.class;Class c3 = new Integer(6).getClass();System.out.println(" C1 == C2 ? :" + (c1 == c2) + " , C1=C3?" + (c1 == c3));System.out.println(" C1.equals(C2) ? :" + c1.equals(c2));System.out.println( "Identity : C1 =" + System.identityHashCode(c1) + ", C2 ="+ System.identityHashCode(c2) + ", C3 =" + System.identityHashCode(c3)); 各位大虾们,求助T_T(初学者) 求struts2 多文件上传进度条demo 我想利用用户控件来改变窗口中的某个pane,怎样实现呀? java,Swing中图片滚动问题,看看我的程序为什么会出现图片重叠的情况呢 java初学者 问个JTable的wenti? 急呀.懂java有谁能帮我一下. 请问一下怎么样用JAVA播放声音呢 怎样得到系统字体? 用tab键切换控件焦点的问题 为什么JLable不能循环更新显示图片 Print函数 调试出错, 帮忙看一下问题出在那里啊?
在必须用抽象的时候,比如所以 Collection , Map 之类的, 就要用 Wrapper,
如果是在 Class 中用 Reflection 时需要 基本类型的参数据, 用 Wrapper 就行, 会自动处理转换,
如果你明确指定要找一个基本类型为参数的方法 ,可以用 Integer.TYPE 这种方式, 或者直接用 int.class , 因为 Class 对象有个 isPrimitive () 方法, 所以 new Integer().getClass() 和 int.class 得到的是不同的东西 , JVM 会区分的.测试一下:
Class c1 = new Integer(5).getClass();
Class c2 = int.class;
Class c3 = new Integer(6).getClass();
System.out.println(" C1 == C2 ? :" + (c1 == c2) + " , C1=C3?" + (c1 == c3));
System.out.println(" C1.equals(C2) ? :" + c1.equals(c2));
System.out.println(
"Identity : C1 =" + System.identityHashCode(c1)
+ ", C2 ="+ System.identityHashCode(c2)
+ ", C3 =" + System.identityHashCode(c3));