首页 > 编程语言 > 详细

java基础复习 - 自动装箱

时间:2015-09-06 21:21:05      阅读:221      评论:0      收藏:0      [点我收藏+]
Integer a = 127; // 将整形127装箱对象
Integer b = 127; // 同上
        
System.out.print( a==b ); // true
System.out.print(a.equals(b)); // true

Integer a = 127 实际为Integer a = new Integer(127);

Integer a = 128;
Integer b = 128;
        
System.out.print( a==b ); // false 
System.out.print(a.equals(b)); // true

127与128 == 运行结果不同的原因在于,当值为小于一个字节时不会再占用另外一个空间,也就是说第一个代码块中a与b占用的是同一块内存,所以为true,但是第二块代码中则不是

java基础复习 - 自动装箱

原文:http://www.cnblogs.com/orlion/p/4787068.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!