Consider below code snap.
we use equals()
to compare objects are meaningfully equivalent or not ?
Here both value are meaningfully equal but why does longWrapper.equals(0)
return false
?
And when I compared both value with ==
operator it returns true
.
Long longWrapper = 0L;
long longPrimitive = 0;
System.out.println(longWrapper == 0L); // true
System.out.println(longWrapper == 0); //true
System.out.println(longWrapper == longPrimitive); //true
System.out.println(longWrapper.equals(0L)); //true
System.out.println(longWrapper.equals(0)); //false
System.out.println(longWrapper.equals(longPrimitive)); //true