我有代码:
class A {
override def toString = "object class A"
}
class B extends A {
override def toString = "object class B"
}
class Cell[+T](init: T) {
private[this] var current: T = init
def get: T = current
def set(x: T) { current = x }
}
val cB = new Cell[B](new B)
println(cB.get)
val cA: Cell[A] = cB
println(cA.get)
但我有错误:def set(x: T) { current = x }
错误:协变类型 T 出现在值 x def set(x: T) { current = x } 的类型 T 的逆变位置
请解释