10
import scala.collection._
trait Foo[A, +This <: SortedSet[A] with SortedSetLike[A,This]]
extends SortedSetLike[A, This] { this: This =>
def bar: This = (this: SortedSetLike[A,This]).empty
}
但如果上溯造型被删除它未能编译:
import scala.collection._
trait Foo[A, +This <: SortedSet[A] with SortedSetLike[A,This]]
extends SortedSetLike[A, This] { this: This =>
def bar: This = this.empty
}
为什么?从extends
子句我们知道Foo
是SortedSetLike[A, This]
,所以upcast当然是有效的 - 但是这不表明编译器允许发生冲突继承吗?
我不知道这种情况的具体细节,但它是可能发生的可怕事情的另一个例子,因为子类中的方法可能比它们实现的方法签名具有更多特定的返回类型。 –