首页 > 编程语言 > 详细

java 自动拆箱

时间:2019-03-04 12:56:24      阅读:145      评论:0      收藏:0      [点我收藏+]
      Integer a0 = 127;
      Integer a1 = 127;
      Integer b0 = 128;
      Integer b1 = 128;
      int c = 128;
      
      
      System.out.println(a0 == a1);  >>>> true //Integer 对象-128 ~ 127 会缓存,不会新建对象 所以相等
      
      System.out.println(b0 == b1);  >>>> false //对象-128 ~ 127 会缓存  但是之外的数据会重新new 
      
      System.out.println(b0 == c);   >>>> true //这里Integer 会自动拆箱成int类型

 

java 自动拆箱

原文:https://www.cnblogs.com/interfacehwx/p/10469968.html

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