码迷,mamicode.com
首页 > 编程语言 > 详细

java 自动拆箱

时间:2019-03-04 12:50:08      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:pre   color   style   类型   -128   out   对象   nbsp   bsp   

      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 自动拆箱

标签:pre   color   style   类型   -128   out   对象   nbsp   bsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!