我在 Java (JDK 1.7) 中偶然发现了这一点:
Integer a = 100;
Integer b = 100;
Integer c = 1000;
Integer d = 1000;
System.out.println(a == b); //true
System.out.println(c == d); //false
System.out.println(new Integer(100) == new Integer(100)); //false
System.out.println(new Integer(1000) == new Integer(1000)); //false
输出为:真假假假
为什么 a==b 评估为真?这是什么原因?这类似于字符串内部化吗?