scala> class A
defined class A
scala> class B {this: A => }
defined class B
scala> new B
<console>:10: error: class B cannot be instantiated because it does not conform
to its self-type B with A
new B
^
ClassB
は self 型を classA
に設定するため、クラスB
(またはそのサブクラス) は class を拡張A
して のインスタンスを作成する必要がありますB
。しかし、のサブクラスはB
1つのクラスしか拡張できないため(これはクラスB
です)、これはまったく可能ですか?
したがって、これは私に質問につながります.クラスの自己型を別のクラスに宣言することは意味がありますか?