scalaobjectlistbuffer

Scala: Objects have same class have different type?


After defining a class in scala, the object that I create seems to be of different type. Trying to create a ListBuffer of objects. Trying out in scala command line. Can someone explain this?

In the example bellow I create a class z. Object p and q seem to conflict when trying to add them to a ListBuffer

scala> class z()
defined class z

scala> var p = new z()
p: this.z = z@3755c76

scala> var q = new z()
q: this.z = z@63f8feb3

scala> var LB = ListBuffer[z](p,q)
<console>:19: error: type mismatch;
 found   : this.z
 required: this.z
       var LB = ListBuffer[z](p,q)
                              ^
<console>:19: error: type mismatch;    
 found   : this.z
 required: this.z
       var LB = ListBuffer[z](p,q)
                                ^

Solution

  • This is an artifact of the current Spark Shell implementation (your example works fine in a regular Scala 2.9.3 shell); there's a post on the spark-users mailing list that explains the problem in more detail and lists a few workarounds.