简体   繁体   English

Scala:具有相同类的对象具有不同的类型?

[英]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.

相关问题 同一类的对象有不同的方法签名 - objects of same class have different methods signature 具有相同类的不同模板的Scala嵌套对象 - Scala nested objects with different template of same class Scala-如何使自定义排序的SortedSet包含多个不同的对象,这些对象具有相同的排序值? - Scala - how to make the SortedSet with custom ordering hold multiple different objects that have the same value by which we sort? Scala:为什么可变Map和不可变Map在同一个自定义类实例上有不同的结果? - Scala: why mutable Map and immutable Map have different result on same custom class instance as key? Scala类型类可以具有抽象类型成员吗? - Can a scala type class have abstract type members? Scala-相同但不同的类型 - Scala - same but different type Scala 双重定义(2 个方法具有相同的类型擦除) - Scala double definition (2 methods have the same type erasure) 在Scala中,所有抽象类型在擦除后都具有相同的类型 - In Scala all abstract types have the same type after erasure Scala:为什么我的案例类实例具有相同的hashCode? - Scala: why do my case class instances have the same hashCode? 如何使用无形HList具有相同类型但具有不同泛型的列表? - How to use shapeless HList to have a list of the same type but with a different generic?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM