Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why we need to override equals and hascode

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we need to override methods of object hashcode
and equals in case of Hashtable and RMI
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sitaram,
A HashTable (or HashMap in the Collections API) stores data based on a certain value. It calls the hashCode() method to see where the value should be stored. There is also a rule that if you implement hashCode(), you must also implement equals() and vice versa. This is for consistency purposes as objects that are equal must have the same hash code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic