我對下面的一段代碼問題:平等運算符,奇數結果?
public class Equivalence {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
System.out.println(n1 == n2);
System.out.println(n1 != n2);
}
}
輸出的結果讓我大吃一驚:
false
true
我已經檢查在Javadoc中的構造網絡,從沒有什麼幫助。
在此先感謝
謝謝
http://stackoverflow.com/q/7520432/422353 – madth3
http://stackoverflow.com/questions/1514910/when-comparing-two-integers-in-java-does-auto-取消裝箱發生 – david