题目:
public static void main(String[] args) { Integer a = 100, b = 100; Integer c = 150, d = 150; System.out.println(a == b); System.out.println(c == d); }
输出结果:
true
false
结论:
1. 如果没有通过属性配置high的值,这默认为127。low的值为-128。
2. Integer 类型的值在[-128,127] 区间,用 “==”则为true。 其他值都是通过new Integer(i)返回的,重新开辟了内存新建了对象,不同对象之间必然为false。
3.Integer对象判断是否相等可使用equals或.intValue()方法,intValue()方法返回int类型,int为基本类型,判断是否相等就是可使用==