鉴于:
trait Mixin {}
case class A(a: Int) extends Mixin
case object B extends Mixin
trait Base {
val m = A(1)
}
trait Sub extends Base {
override val m = B // does. not. compute.
}
我在trait Sub
中收到编译错误:
<console>:18: error: overriding value m in trait Base of type A;
value m has incompatible type
override val m = B // does. not. compute.
^
为什么? case对象继承了正确的trait,就像case类一样 . 这是Scala 2.10 .
1 回答
你需要制作类型
Mixin
的m
: