I have written a program like below :
public class Boxing6 {
public static void main(
String[] args) {
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
boolean b3 = true;
Boolean b4 = true;
System.out.println(b1 == b2);
System.out.println(b1 == b3);
System.out.println(b3 == b4);
System.out.println(b1 == b4);
}
}
and i am getting the Response as :
false
true
true
false
Could some one explain why is it so ?
Because when i see the statement from
SCJP Certification Book it's like this:
In order to save memory, two instances of the
following wrapper objects will always be == when their primitive values are the same:
n Boolean
n Byte
n Character from \u0000 to \u007f (7f is 127 in decimal)
n Short and Integer from -128 to 127