==
的不同作用- 对于对象引用类型:比较的是对象的内存地址。
对于基本数据类型:比较的是值。
如果整型字面量的值在-128到127之间
,那么自动装箱时不会new新的Integer对象,而是直接引用 常量池中的Integer对象,超过范围 a1==b1的结果是false
public class string02 {
public static void main(String[] args) {
Integer a=128;
Integer b=128;
System.out.println(a==b);//false
Integer c=127;
Integer d=127;
System.out.println(c==d);//true
}
}