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

Compatibility of hash codes between Long and BigInt #11792

Closed
denisrosset opened this issue Nov 5, 2019 · 5 comments
Closed

Compatibility of hash codes between Long and BigInt #11792

denisrosset opened this issue Nov 5, 2019 · 5 comments

Comments

@denisrosset
Copy link

Here is a small example:

scala> BigInt(-1L).hashCode
res0: Int = -1

scala> (-1L).hashCode
res1: Int = 0

see scala/scala#8526

@sjrd
Copy link
Member

sjrd commented Nov 5, 2019

You'll want to compare (-1L).## to BigInt(-1L).## for consistent results. hashCode does not honor cooperative equality and hash code.

@denisrosset
Copy link
Author

If I get it, (x: AnyRef).## == (x: AnyRef).hashCode, while it differs for the primitive types, right?

@denisrosset
Copy link
Author

Corrected the test.

@sjrd
Copy link
Member

sjrd commented Nov 5, 2019

Yes that's basically right, modulo box classes, which behave like primitives.

@denisrosset
Copy link
Author

Closing this as it's not a real issue, thanks @sjrd

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