码迷,mamicode.com
首页 > 其他好文 > 详细

Integer的等于判断

时间:2016-09-23 16:30:26      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

Integer c = 3;
Integer d = 3;
Integer e = 321;
Integer f = 321;
System.out.println(c == d);    true
System.out.println(e == f);    false

 

原因如下

static final Integer cache[] = new Integer[-(-128) + 127 + 1];
 
static 
{
    for(int i = 0; i < cache.length; i++)
    cache[i] = new Integer(i - 128);
}

小于128的会用常量池中的 不会new Integer,大于128会new Integer

Integer的等于判断

标签:

原文地址:http://www.cnblogs.com/jin12/p/5900375.html

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