File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Override hashCode method

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we dont override the hashCode method then how the objects are stored inside HashSet and will all the objects inside HashSet have the same hashCode?
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MaheshS Kumbhar wrote:If we dont override the hashCode method then how the objects are stored inside HashSet and will all the objects inside HashSet have the same hashCode?


If you don't override the hashcode, the hashcode method from the Object class will be used, which returns the identity hashcode -- and if you overridden equals() (but not hashcode), then depending on what you did, you can corrupt the HashSet.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic