It is true that the explanation offered in the book is questionable, but to be fair it was more believable when they wrote it. It's still true in 2.8, but we have to retrofit different reasoning because as you've noticed, all the other collections do element comparisons even if they're mutable.
A lot of blood had been shed trying to make Arrays seem like the rest of the collections, but this was a tremendously leaky abstraction and in the end it was impossible. It was determined, correctly I think, that we should go to the other extreme and supply native arrays the way they are, using implicit machinery to enhance their capabilities. Where this most noticeably falls down is toString and equals, because neither of them behaves in a reasonable fashion on Arrays, but we cannot intercept those calls with implicit conversions because they are defined on java.lang.Object. (Conversions only happen when an expression doesn't type check, and those always type check.)
So you can pick your explanation, but in the end arrays are treated fundamentally differently by the underlying architecture and there's no way to paper over that without paying a price somewhere. It's not a terrible situation, but it is something you have to be aware of.
It's all about referential transparency. The idea is, if two values are
==, it shouldn't matter which one you use for something. If you have two arrays with the same contents, it clearly matters which one you modify, so
== returns false unless they are the same one.
This exact question has been voiced many times (by myself too, see Strange behaviour of the Array type ).
Note that it is ONLY the
Array collection that does not support
==, all other collections do. The root cause is that
Array IS the Java
- Why doesn't Array's == function return true for Array(1,2) == Array(1,2)?
- Why scala cannot infer common return type for a function with multiple parameter lists?
- Why does Scala not have a return/unit function defined for each monad (in contrast to Haskell)?
- Why does Scala require a return type for recursive functions?
- Why is method overloading not defined for different return types?
- Why doesn't a prism set function return an Option/Maybe
- Why does a partial function applied to 2 functions that do the same thing defined in 2 different ways return a different result?
- Why does scalaz's implementation of Monoid for Option evaluate the f2 function twice?
- EitherT: Call function returning Either only if a certain condition is true (otherwise return right)
- When using scala path dependent type as function codomain, why is it impossible to add alias for that function?
- Why parameter type is needed for expanded function when there are more than 1 parameter?
- Performance of tail function for Scala Arrays
- Why Scala implement andThen function only for Function1
- Why is it better to use case in function args for pattern matching in a map function
- Why does TypeTag not work for return types?
- Why if for V <: Seq[Int] when V is a Seq descendant map and zip operations return a Seq[Int]
- Why can't I use the constructor of a case class as a function for use inside map()
- Why doesn't my recursive function return the max value of a List
- Why does getActualTypeArguments return Object instead of Integer for Option[Int]?
- Why does the compiler infer incorrectly return type for Future.sequence declaration in function?
- Waiting for another future to end to return a function
- Why does scala return a Any(Val/Ref) when the function is obviously called with wrong types
- Function to return the same output for any input in Scala
- Why does apply with function parameter fail for println and not print?
- How to specify return type for nested arrays of arbitrary nesting length?
- why does sameElements returns true for sets?
- Unable to infer SQL type for my user-defined function which return BigInt
- why does Scala function accepts case class type for a function argument?
- In Scala, why does a type annotation must follow for the function parameters ? Why does the compiler not infer the function parameter types?
- Why map function in scala not reading Arrays
More Query from same tag
- Scala simple class design
- How to modify content of default artifact with SBT
- Scala Pattern Matching with Sets
- reading multiple lines as input in scala
- Set changing scala project dependency in Intellij IDEA 14 (for code completion and inspection)
- Scala: Most idiomatic way to conditionally execute one Future depending on another?
- Mapped projection with <> to a case class with companion object in Slick
- Accessing the default JDBC database in Play for Scala
- Currying Example in Scala
- Returning Error for Invalid Parse inside of `rep`
- scala 3 opaque type: cannot call methods defined in extension
- Is possible for a worker to be a coordinator and send to other workers in Spark?
- SLF4J Initialization - Substitute Loggers
- Improve this actor calling futures
- Best way to score and sum in Scala?
- Is there atomic broadcast in akka?
- Scala type erasure in pattern matching Map[String, Int]
- Multi-Assignment based on Collection
- Can SparkContext.textFile be used with a custom receiver?
- Conversion from bson.Document to JsObject and applying reads on it with joda.DateTime
- Implement weak-referenced Eventbus actors?
- flatMap results when read from a file is different from same line passed as a string
- Scala 2.10 vs. 2.9 incompatibilities
- Ambiguous overload even one is more specific
- Scala Spark: Flatten Array of Key/Value structs
- how to set sbt proxy in windows
- How to use collect_set and collect_list functions in windowed aggregation in Spark 1.6?
- multi-assignment on a Seq[Tuple2]
- Use Argonaut in Play framework with Reads and Writes
- how to generate new column values for each group using a condition