which implies to me that comparing wrappers and primitives, regardless of whether boxing takes place, always works with == and !=.
Am I right or have I misunderstood the objective?
Jacob Sonia wrote:Hi, when i read this i understood this:
if we say
Integer i = 127;
Integer j = 127;
if(i == j) //returns true;
Integer i = 129;
Integer j = 129;
if(i == j) // returns false;
but it will not work here because using new always create a new object, so == starts comparing references now
Integer i = new Integer(127);
Integer j = new Integer(127);
if(i == j) //returns false
Correct me if i am wrong
AmitKumar Jain wrote:Hi Bob,
I disagree slightly. Though you are correct, the statement requires correction.
== in case of references, checks whether the references point to the same object.
[ == in no way can compare objects , it just compares the references , which are
nothing but object handles ]