Forums Register Login
equals( ) explanation ?
What two statements are true about properly overridden hashCode() and equals()methods?

C. hashCode() can always return the same value, regardless of the object that invoked it.sure

E. equals() can be true even if it�s comparing different objects. why???what's the meaning of this???


[ October 15, 2006: Message edited by: saied ims ]

(removed shout in title)
[ October 15, 2006: Message edited by: Barry Gaunt ]
The definition of equals is up to the programmer. The only thing that you are required to do when you override the equals method is to return a boolean.
The job of equals() is to compare two different objects meaningfully. This means you can have 2 separate references to 2 different objects and if the 2 objects are same according to the definition provided by the programmer, equals() will return true.

The default implementation of equals() in Object returns true only if you have references to the same object. You are expected to override it so that it returns true even if you have two different objects that are semantically equivalent.
[ October 15, 2006: Message edited by: Aniket Patil ]
thanks all
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Nov 25, 2017 03:05:29.