// 當建立範圍爲[-128,127]時 Integer a = 1; Integer b = 1; Integer c = new Integer(1); System.out.println("a == b :" + (a == b)); System.out.println("a == c :" + (a == c)); System.out.println(); // 當建立範圍不爲[-128,127]時 Integer d = 128; Integer e = 128; Integer f = new Integer(128); System.out.println("d == e :" + (d == e)); System.out.println("d == f :" + (d == f)); System.out.println("d e f 互不相等(false爲正確測試結果):" + (d == e || d == f || e == f)); System.out.println(); // 包裝類均爲值傳遞 Integer g = 0; Integer h = new Integer(130); Test1(g); Test2(h); System.out.println("g = "+g); System.out.println("h = "+h); } static void Test1(Integer t) { t = 1; System.out.println("Test1內: t = " + t); } static void Test2(Integer t) { t = 131; System.out.println("Test2內: t = " + t); } } 原文:https://blog.csdn.net/Cactus_Lrg/article/details/81489299
測試結果以下:測試
a == b :true
a == c :falsespa
d == e :false
d == f :false
d e f 互不相等(false爲正確測試結果):false.net
Test1內: t = 1
Test2內: t = 131
g = 0
h = 1303d