Quantcast
Channel: How should I map long to int in hashCode()? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

How should I map long to int in hashCode()?

$
0
0

I have a range of objects that have a long field whose value uniquely identifies a particular object across my entire system, much like a GUID. I have overriden Object.equals() to use this id for comparison, beause I want it to work with copies of the object. Now I want to override Object.hashCode(), too, which basically means mapping my long to some int return value.

If I understood the purpose of hashCode correctly, it is mainly used in hash tables, so a uniform distribution would be desirable. This would mean, simply returning id % 2^32 would suffice. Is that all, or should I be aware of something else?


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images