我一直在尝试一些小东西来尝试理解 Scala 的 Variance 和 Type Bounds 语法。
class Animal() {
def says():String = "???"
}
class Dog() extends Animal {
override def says():String = "woof"
}
val adog = new Dog
class Zoo[A <: Animal](thing: A) {
def whoami()=thing.getClass
def chat()=thing.says
}
但是,当我尝试创建对象的实例时,我得到:
scala> val cage = new Zoo[Dog](adog)
<console>:18: error: type mismatch;
found : this.Dog
required: this.Dog
val cage = new Zoo[Dog](adog)
我不太明白编译器告诉我什么?
tks