我一直在尝试一些小事来尝试理解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