このコードを機能させるのに問題があります。それを継承するクラスが「子」を持つことを可能にする特性を作成したいのですが、どうやらChild
のsetParent
メソッドは を望んP
でいますが、Parent[P, C]
代わりに を取得します。
package net.fluffy8x.thsch.entity
import scala.collection.mutable.Set
trait Parent[P, C <: Child[C, P]] {
protected val children: Set[C]
def register(c: C) = {
children += c
c.setParent(this) // this doesn't compile
}
}
trait Child[C, P <: Parent[P, C]] {
protected var parent: P
def setParent(p: P) = parent = p
}