java-multihash icon indicating copy to clipboard operation
java-multihash copied to clipboard

Fix Multihash.Type.hashCode()

Open vorburger opened this issue 2 years ago • 3 comments

Given that Multihash.hashCode() invokes Multihash.hashCode(), and e.g. https://madhead.me/posts/enums-fuckup/, this seems more appropriate.

vorburger avatar Jan 02 '24 17:01 vorburger

Do I understand correctly that the same Multihash object may have different hash codes in two different JVM instances of the same version? Because if you aim for hash code stability across different JVM versions, I'm afraid it isn't guaranteed even for String.

odisseus avatar Jan 03 '24 14:01 odisseus

Do I understand correctly that the same Multihash object may have different hash codes in two different JVM instances of the same version? Because if you aim for hash code stability across different JVM versions, I'm afraid it isn't guaranteed even for String.

This proposes to use the (stable) index, not String, for Type; and for Multihash there's no String. Or did I misunderstand your comment?

Merge this as-is?

vorburger avatar Jan 05 '24 14:01 vorburger

AFAIK the exact algorithm of calculating the hash code is not part of the Java specification, even for common types such as String or Integer. My point was that it's probably impossible to guarantee that the hash code of the same object will stay the same across different JVM instances in the general case.

That said, I don't object to merging this PR.

odisseus avatar Jan 05 '24 19:01 odisseus