Recently an interviewer asked me that I have a class where I have overriden its equals()
method but have not overridden my hashCode()
method.
Now is it necessary to override my hashCode()
method too.?
What will happen if i don't override my hashcode method, will set maintain its unique property of not allowing duplicates.?
The question is all about internal implementation of Set
and here my confusion is if two objects return different hashCode()
, according to me their equals()
won't be checked and then the unique property of Set
will be violated if the two objects came out to be equal.
Is that true.?