• Post Reply Bookmark Topic Watch Topic
  • New Topic

hashcode() and equal() method  RSS feed

 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why we need to override the equal() and hashcode() ,when it already exist in object class?


Thanks in advance
 
Campbell Ritchie
Marshal
Posts: 55785
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you often need to know that two objects have the same state as each other.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also download and read Chapter 3 of the excellent Effective Java, which is about equality and comparison.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!