给定以下代码:
class A {
class B
type C <: B
trait D
}
class E extends A {
type C = B
}
class F extends E {
override type C = B with D
}
为什么Scala IDE中的Eclipse Indigo IDE的展示编译器会出现错误信息“overriding type C in class E,which equals F.this.B; type C has incompatible type”?
毕竟,类“B”只是通过特质“D”进行了“修饰”,因此两个类型定义具有相同的基本类型,即“B”。因此,它们是兼容的类型定义。
下面的代码可以正常工作。我认为类型赋值的规则与变量赋值类似,例如:
class Foo
trait Bar
val a: Foo = new Foo
val fooWithBar: Foo = new Foo with Bar
我理解错了吗?