(Scala 2.11.8)
考虑以下代码段:
class Case2 {
trait Container[+A] {
def addAll[B >: A, T2 <: Container[B]](that: T2): Boolean
}
def t1: Container[String] = ???
def t2: Container[Int] = ???
// Works
t1.addAll[Any, Container[Any]](t2)
// Errors:
//* type mismatch; found : Case2.this.Container[Int] required: T2
//* inferred type arguments [String,Case2.this.Container[Int]] do not conform to method addAll's type parameter bounds [B >: String,T2 <: Case2.this.Container[B]]
t1.addAll(t2)
}
为什么最后一次addAll
调用不能推论正确的最小公共超类型?
创建了一张票证,该票证由于“超出范围”而关闭,由Adriaan Moors引用:
类型推断不支持引用其他类型参数的范围。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句