• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding Object.equals()  RSS feed

 
Gary Fletcher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick theoretical question.

I've read that if overriding Object.equals() then Object.hashCode() must also be overriden. Is this true in the case of the below overriden equals() method?



This is simply a theoretical question for clarification, I don't have this in any code.
 
Claude Moore
Ranch Hand
Posts: 924
9
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, try and answer yourself: why overriding of equals() and hashCode() s required? Which is its purpose?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also have a look at the general contract for hashCode and see whether that version of equals will cause hashCode to violate its general contract.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!