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
}
}
Wie x==y
kommen wahr und a==b
ist falsch? Wenn es auf dem Wert (Integer -128 To 127
) basiert, dann sollte 'a'
-128
richtig drucken?Referenz Vergleich mit == Operator
Der Bereich von 'Integer' ist -2^31 zu 2^31 - 1. Es ist nicht -128 zu 127; das ist der Bereich eines 'Bytes'. –