Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Multihash.Type.hashCode() #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vorburger
Copy link

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

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

odisseus commented Jan 3, 2024

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.

@vorburger
Copy link
Author

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?

@odisseus
Copy link
Contributor

odisseus commented Jan 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants