[英]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. 在Scala中定义一个类后,我创建的对象似乎是不同类型的。 Trying to create a ListBuffer of objects. 尝试创建对象的ListBuffer。 Trying out in scala command line. 在scala命令行中尝试。 Can someone explain this? 有人可以解释吗?
In the example bellow I create a class z
. 在下面的示例中,我创建了一个class z
。 Object p and q seem to conflict when trying to add them to a ListBuffer
尝试将对象p和q添加到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)
^
This is an artifact of the current Spark Shell implementation (your example works fine in a regular Scala 2.9.3 shell); 这是当前Spark Shell实现的产物(您的示例在常规的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. spark-users邮件列表上有一个帖子 ,更详细地解释了该问题,并列出了一些解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.