As I understand it equal hash codes in general imply a high probability of equality between objects, but they aren't perfect. But I've been told that in Java the base hash code of an Object is simply the memory address of the object, so I've assumed that Object hash codes are effectively perfect(two objects can't occupy the same space in memory right?). But I've been relaying very heavily on this assumption for a program I'm writing and I've started to think I should really get a definitive answer on this instead of continuing with my assumption.
OffbeatPatriot
5
Junior Poster in Training
Recommended Answers
Jump to PostNo, it seems that it isn't safe to make such an assumption. As per this article:
the default implementation of hashCode() provided by Object is derived by mapping the memory address of the …
Jump to PostDon't use hashcode to imply equality(). You can read the hashCode() method documentation here, it explains how what you've said is not a guarantee. Besides, if you don't care about logical equality (i.e. …
All 6 Replies
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
BestJewSinceJC
700
Posting Maven
wildplace
0
Junior Poster in Training
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
OffbeatPatriot
5
Junior Poster in Training
jwenting
1,889
duckman
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.