Scala 为什么不在;K<;:";can';协方差是什么?
Scala代码:Scala 为什么不在;K<;:";can';协方差是什么?,scala,type-systems,type-bounds,Scala,Type Systems,Type Bounds,Scala代码: class Cat[T] { def meow[K <: T] = "" } class Cat[-T] { def meow[K <: T] = "" } 编译器将打印: error: covariant type T occurs in contravariant position in type <: T of type K def meow[K <: T] = "" ^ 错误:
class Cat[T] {
def meow[K <: T] = ""
}
class Cat[-T] {
def meow[K <: T] = ""
}
编译器将打印:
error: covariant type T occurs in contravariant position in type <: T of type K
def meow[K <: T] = ""
^
错误:协变类型T出现在类型中的逆变位置,这是不合理的
在“K”中使用JazzT
error: covariant type T occurs in contravariant position in type <: T of type K
def meow[K <: T] = ""
^