I have these two object which have all equal fields.
Why does obj1.equals(obj2)
return false?
I have these two object which have all equal fields.
Why does obj1.equals(obj2)
return false?
This is the default behaviour of equals(comparing references). So, if ==
returns false on Object, .equals()
returns false as well. Unless you have overidden equals()
.
If you don't override equals method, then when you are doing
obj1.equals(obj2)
It is comparing the values as displayed in your image.
"com.waze.testing.data.Pin@4355".equals("com.waze.testing.data.Pin@4361")
which will returns false
as per your result.
Did you override .equals()
? If not, it is using Object.equals()
which only returns true if they are the exact same instance.