• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What's wrong with my hashCode() ?

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)







 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
Marshal
Posts: 79180
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you start your variable names with underscores?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic