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

NBT classes do not implement hashCode when implementing equals #15

Closed
Marcono1234 opened this issue Dec 9, 2018 · 1 comment
Closed

Comments

@Marcono1234
Copy link
Contributor

The NBT classes implement equals, but not hashCode. The java-doc says that both should be implemented:

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

@Querz
Copy link
Owner

Querz commented Dec 9, 2018

You're right, here's a pull request that fixes this: #17

equals() works by actually checking all keys and values, this means hashCode() needs to do the same to comply with the java-doc (which might cause some performance issues when used on huge NBT structures).
The implementation of hashCode() does currently not affect the NBT implementation, because the only thing that calculates hash codes is the CompoundTag which is using a HashMap which in turn only ever has Strings as keys, not Tags.

@Querz Querz closed this as completed Dec 11, 2018
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

No branches or pull requests

2 participants