首页 > 系统服务 > 详细

对Integer类中的私有IntegerCache缓存类的一点记录

时间:2018-06-10 14:03:06      阅读:257      评论:0      收藏:0      [点我收藏+]

对Integer类中的私有IntegerCache缓存类的一点记录

  // Integer类有内部缓存,存贮着-128 到 127。
  // 所以,每个使用这些数字的变量都指向同一个缓存数据
  // 因此可以直接使用 == 来比较是否相等
  Integer a = 88;
  Integer b = 88;
  System.out.println(a == b); // true

  // 下面这个不在Integer缓存类里的数字,在每次赋值的时候都会新建一个对象存放
  // 所以,它们不能使用 == 来判断是否相等,而只能使用equals方法来比较
  Integer d = 800;
  Integer c = 800;
  System.out.println(d == c); // false
  System.out.println(d.equals(c)); // true

对Integer类中的私有IntegerCache缓存类的一点记录

原文:https://www.cnblogs.com/molisiye/p/9162483.html

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