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

Array.hashCode should acually hash the data contained #1607

Closed
scabug opened this issue Dec 29, 2008 · 5 comments
Closed

Array.hashCode should acually hash the data contained #1607

scabug opened this issue Dec 29, 2008 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Dec 29, 2008

Currently, Array.hashCode returns different values for different arrays, even if they contain the same data.

Example: Array(1,2,3).hashCode == Array(1,2,3).hashCode returns false while List(1,2,3).hashCode == List(1,2,3).hashCode returns true.

@scabug
Copy link
Author

scabug commented Dec 29, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1607?orig=1
Reporter: pascalg

@scabug
Copy link
Author

scabug commented Jan 4, 2009

Mohsen Lesani [X] (lesani) said:

scala>  Array(1,2,3).hashCode == Array(1,2,3).hashCode
res0: Boolean = false

scala> List(1,2,3).hashCode == List(1,2,3).hashCode
res1: Boolean = true

The same in Trunk.

@scabug
Copy link
Author

scabug commented Jan 4, 2009

@odersky said:
Arrays are not lists. In particular, arrays are mutable, which means completely different design criteria for hashcode and equals.

@scabug scabug closed this as completed May 18, 2011
@scabug
Copy link
Author

scabug commented Mar 31, 2016

Simon Sotak (the21st) said (edited on Mar 31, 2016 2:51:29 PM UTC):
But the same thing works as expected for mutable scala collections, so shouldn't it work for (mutable) Arrays?

scala> mutable.Seq(1, 2).hashCode == mutable.Seq(1, 2).hashCode
res0: Boolean = true

@scabug
Copy link
Author

scabug commented Apr 1, 2016

@SethTisue said:
since Scala 2.8, Scala arrays are just Java arrays, so we aren't free to make the hashCode method return a different answer than Java does.

scala.collection.mutable.WrappedArray, on the other hand, behaves as you would like.

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