我有以下代碼。錯誤的整數比較值輸出
public static void doIntCompareProcess() {
int a = 100;
int b = 100;
Integer c = 200;
Integer d = 200;
int f = 20000;
int e = 20000;
System.out.println(c == d);
compareInt(e, f);
compareInt(a, b);
}
public static void compareInt(Integer v1, Integer v2) {
System.out.println(v1 == v2);
}
這給了我這樣的輸出:
false
false
true
凡當期的輸出應該是:
false
false
false
爲什麼我收到的代碼錯誤輸出?
但參數是'Integer'類 –
@BhavikAmbani:請參閱更新的答案。 – NPE
這是一個棘手的問題,令人驚訝的是我們經常忘記它。很好的答案! – Ewald