public static void main(String[] args) {
Integer t1 = 129;
Integer t2 = 129;
System.out.println(t1 == t2);
}
输出的结果竟然是 false 无法想象
在使用easyUI树时判断子类时
if(model.getId().equals(info.getParentId())) {
业务代码省略......
}
model.getId() 值为128
info.getParentId() 值为128
但完美地跳过了我的业务代码
在参考:https://blog.csdn.net/weixin_38361347/article/details/81916620 下参考了源码
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
Integer缓存了-128~127之间的数,这是在类加载期间就完成的。以后需要的时候直接指向它就可以了,省去了构造对象的开支,提高了效率。而大于127的数就需要重新指向了
===================================== 快乐的修改线 ==============================================
补充两张图片
Float和 Doule在什么情况下两个相等的数字用 == 比较都为false
Integer和Long一样 在-128到127相等。