• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's wrong with my hashCode() ?

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am calling different instances, however, it returns the same hashCode() for different instances:


returns
172 [main] DEBUG poker.Poker - 217
172 [main] DEBUG poker.Poker - 217
172 [main] DEBUG poker.Poker - 217

Not sure why they are being returned in triplicate either.



returns
172 [main] DEBUG poker.Poker - 217
...(x3)







 
Henry Wong
author
Marshal
Pie
Posts: 21497
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It would help if you print out more details -- such as "name" or other parts of the instance, in addition to the hash code. We don't know anything about the instances that you are referring to.

And BTW, it is valid for two unequal instances to have the same hash code -- so there may be nothing wrong.

Henry
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:

It would help if you print out more details -- such as "name" or other parts of the instance, in addition to the hash code. We don't know anything about the instances that you are referring to.

And BTW, it is valid for two unequal instances to have the same hash code -- so there may be nothing wrong.

Henry


I think I resolved it now:

Output
847 for _name = "Johnny"
847 for _name = "Johnny"
729 for "_name = "Peter"
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you start your variable names with underscores?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic