public class AutoBoxingAndUnBoxing
{
public static void main(String[] args)
{
Integer x = 127;
Integer y = 127;
System.out.println(x == y);//true
Integer a = 128;
Integer b = 128;
System.out.println(a == b);//false
System.out.println(a); // prints 128
}
}
x==y
是怎麼回事a==b
是錯誤的?如果它是基於值(Integer -128 To 127
),那麼'a'
應該打印-128
對不對?使用==運算符進行參考比較
「整數」的範圍是-2^31到2^31 - 1。它不是-128到127;這是'byte'的範圍。 –