Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashCode help

 
Steve Chambers
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully someone can help me with this issue: I have a structure (suffix tree) that is built using hashmaps. In these hashmaps I store objects. Each object has a string field. If anyone is familiar with how a suffix tree works this will make sense.

Basically I store a sequence of objects on the tree. When I add the suffix part to the tree the hashcodes of the object are the same as the hashcode of the orignial object, even though I have instansiated a new object.

Does anyone know why this would be the case? Why am I getting the same hashcode for different objects?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "hashCode()" method you inherit from Object gives you a value that never changes in the life of an individual object. If you want hashCode() to return a value based on the fields in an object, then you need to override it and supply your own version that does this.

Does this answer your question?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic