Read the article . From it I realized that methods need to be redefined, because, for example, when receiving objects from different sessions they may have the same id, and if we override hashCode()
, then they will differ in hash code, right?
One more thing: here , on a similar question, the answer was given: the methods must be overridden for the correct storage of objects in the Hash
and Set
collections. Again, the question is why (if not redefining is not correct, how is it not correct)? Please explain more clearly.
equal()
andhashCode()
. Ifequal()
not overridden, then obets are compared by reference. An override ofhashCode()
is required due to the internal structure of the collection. - jisecayeyo