Java: If I overwrite the .equals method, can I still test for reference equality with ==?
Posted
by shots fired
on Stack Overflow
See other posts from Stack Overflow
or by shots fired
Published on 2010-05-07T23:58:54Z
Indexed on
2010/05/08
0:08 UTC
Read the original article
Hit count: 119
I have the following situation: I need to sort trees based by height, so I made the Tree's comparable using the height attribute. However, I was also told to overwrite the equals and hashCode methods to avoid unpredictable behaviour.
Still, sometimes I may want to compare the references of the roots or something along those lines using ==. Is that still possible or does the == comparison call the equals method?
© Stack Overflow or respective owner