与えられた 2 つの独立した特性:
trait T1 {
def x = 42
}
trait T2 {
def x = 0
}
これらの 2 つの特性が混在するクラスを定義しようとすると、次のようになります。
class C extends T1 with T2
コンパイラ エラーが発生します。
error: overriding method x in trait T1 of type => Int;
method x in trait T2 of type => Int needs `override' modifier
class C extends T1 with T2
^
one error found
ここで、T1 と T2 が個別に開発されたとします。したがって、何もオーバーライドしないため、オーバーライドはありません。では、C はどのように定義できますか? このような:
class C extends T1 with T2 {
override def x = super.x
}
?