すべてが共通の特性を拡張するオブジェクトを返すメソッドを作成しました。戻り値の型をその特性を持つオブジェクトに指定したいと思います。複雑なのは、トレイトが再帰的な型シグネチャを持っていることです。
特に、elastic4sを使用して、 aggregationDefinition traitを見ています。特性の定義は次のとおりです。
trait AggregationDefinition[+Self <: AggregationDefinition[Self, B], B <: AggregationBuilder[B]]
そして、私の方法の簡略版は次のとおりです。
def asAggregation(): AggregationDefinition = {
aggType match {
case "terms" => aggregation.terms(aggName).field(key)
case "cardinality" => aggregation.cardinality(aggName).field(key)
}
}
複雑なのは AggregationDefinition にあり、型パラメーターが必要です。
Error: trait AggregationDefinition takes type parameters
トレイト定義の再帰と相互参照に混乱しており、型パラメーターがどうあるべきかわかりません。型パラメータには何を使用すればよいですか?