没有合适的资源?快使用搜索试试~ 我知道了~
【Java学习】Integer.ValueOf()引发的血案
0 下载量 160 浏览量
2020-12-21
07:43:20
上传
评论
收藏 113KB PDF 举报
温馨提示
试读
2页
这道题有的人或许做过,也可能选对,但是这其中的道理你却不一定理解,在这里大牛走过,小白留下一起学习。 先来分析选型A,Integer i01 = 59,是一个装箱的过程,在进行i01 == i02的比较过程中,因为右边是整型,发生了拆箱的动作,所以进行了值得比较,所以返回true。 在这里拿出Integer a = 59,Integer b = 59,这种又会出现什么状况呢,如果按照装箱和拆箱来看就是true,如果按照对象来看,就是false,在你举棋不定得时候你就应该看看源码了。 /** * Cache to support the object identity semant
资源推荐
资源详情
资源评论
【【Java学习】学习】Integer.ValueOf()引发的血案引发的血案
这道题有的人或许做过,也可能选对,但是这其中的道理你却不一定理解,在这里大牛走过,小白留下一起学习。
先来分析选型A,Integer i01 = 59,是一个装箱的过程,在进行i01 == i02的比较过程中,因为右边是整型,发生了拆箱的动作,所以进行
了值得比较,所以返回true。
在这里拿出Integer a = 59,Integer b = 59,这种又会出现什么状况呢,如果按照装箱和拆箱来看就是true,如果按照对象来看,就是
false,在你举棋不定得时候你就应该看看源码了。
/**
* Cache to support the object identity semantics of autoboxing for values between
* -128 and 127 (inclusive) as required by JLS.
*
* The cache is initialized on first usage. The size of the cache
* may be controlled by the {@code -XX:AutoBoxCacheMax=} option.
* During VM initialization, java.lang.Integer.IntegerCache.high property
* may be set and saved in the private system properties in the
* sun.misc.VM class.
*/
private static class IntegerCache {
static final int low = -128;
static final int high;
static final Integer cache[];
static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the property cannot be parsed into an int, ignore it.
}
}
high = h;
cache = new Integer[(high - low) + 1];
int j = low;
for(int k = 0; k = 127;
}
private IntegerCache() {}
}
资源评论
weixin_38630571
- 粉丝: 8
- 资源: 943
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功