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?