は例えば、次のコードで:なぜ、具体的なメンバーをスカラーで抽象的なメンバーで上書きできないのですか?
class Animal
class Dog extends Animal
trait Base {
def a: Animal = new Dog
}
trait Deri extends Base {
override val a: Dog
}
次のエラーが与えられます。
error: overriding value a in trait Deri of type Dog; method a in trait Base of type => Animal needs to be a stable, immutable value; (Note that value a in trait Deri of type Dog is abstract, and is therefore overridden by concrete method a in trait Base of type => Animal)
Scalaは選択しない間、私は、override
でDeri
でa
を明示的に変更しておりますので、私は、知りたいです(a
をDeri
に置き換えて、Base
のエラーメッセージに示されているように上書きしてください)。
私はあなたの質問に従っわかりません。 'Deri'は' Base'をオーバーライドしようとしていますが、 'Base' *は既にベース実装を提供しているので失敗します。' Deri'は再び抽象化しようとします。 –
@YuvalItzchakovはい、 'Deri'では、aは' Animal'の代わりに 'Dog'型です。 –