Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
equals() returns true if two objects are the same. Otherwise false. hashCode() returns a hashcode for an object. If both methods are correct implemented two objects which are equal have the same hashCode. For own classes you have to override both. But only if you need them. You can read this for more explanation: https://www.baeldung.com/java-equals-hashcode-contracts And here is a code: https://code.sololearn.com/cK2H7CdVEq45/?ref=app
7th Apr 2020, 7:32 PM
Denise Roßberg
Denise Roßberg - avatar