Forums Register Login

What's wrong with my hashCode() ?

+Pie Number of slices to send: Send


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)







+Pie Number of slices to send: Send


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
+Pie Number of slices to send: Send
 

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"
1
+Pie Number of slices to send: Send
Why do you start your variable names with underscores?
He was expelled for perverse baking experiments. This tiny ad is a model student:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 929 times.
Similar Threads
HashCode and equals
code generation of an effective hashCode
why should i need to override hashcode when i override equals method
Logging problem and grammatical problems
== operator....
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:32:16.