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?
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.