scala> import scala.collection.mutable.Buffer
import scala.collection.mutable.Buffer
scala> val b = Buffer(1, 2, 3)
b: scala.collection.mutable.Buffer[Int] = ArrayBuffer(1, 2, 3)
scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)
scala> b == l
res1: Boolean = true
I was wondering, why the Buffer and List object can be compared with a result of true ?
I always thought, that because they are from different classes, they have to be false when compared. Can someone explain me, why it is implemented this way ?
From http://www.scala-lang.org/docu/files/collections-api/collections_41.html
So it’s because scala.collection.mutable.Buffer and List belong to the same category (sequence) and equality is then defined as having equal elements.