「追加」メソッドを持つコレクション (Java コレクションなど) を定義する構造型を定義しようとしています。これを使用して、特定のコレクションを操作するいくつかの高階関数を定義したいと思います
object GenericTypes {
type GenericCollection[T] = { def add(value: T): java.lang.Boolean}
}
import GenericTypes._
trait HigherOrderFunctions[T, CollectionType[X] <: GenericCollection[X]] {
def map[V](fn: (T) => V): CollectionType[V]
....
}
class RichJList[T](list: List[T]) extends HigherOrderFunctions[T, java.util.List]
これは次のエラーでコンパイルされません
error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement
GenericCollection のパラメーターを削除して、メソッドに配置しようとしました:
object GenericTypes {
type GenericCollection = { def add[T](value: T): java.lang.Boolean}
}
import GenericTypes._
trait HigherOrderFunctions[T, CollectionType[X] <: GenericCollection]
class RichJList[T](list: List[T]) extends HigherOrderFunctions[T, java.util.List]
しかし、別のエラーが発生します:
error: type arguments [T,java.util.List] do not conform to trait HigherOrderFunctions's type parameter bounds [T,CollectionType[X] <: org.scala_tools.javautils.j2s.GenericTypes.GenericCollection]
Scala で抽象型パラメーターを使用して構造型付けを使用する方法について、誰かアドバイスをもらえますか? または、私が達成しようとしていることを達成する方法は? 本当にありがとう!