在 Scala 2.10 中,这有效:
implicit class T1[A](val self: Iterator[A]) {
def :+[B >: A](elem: B): Iterator[B] =
self ++ Iterator(elem)
}
但是当我尝试使它成为一个价值类时:
implicit class T2[A](val self: Iterator[A]) extends AnyVal {
def :+[B >: A](elem: B): Iterator[B] =
self ++ Iterator(elem)
}
我得到错误:
type arguments [B] do not conform to method ++'s type parameter bounds [B >: A]
为什么?