2
私は2つのインターフェイスKotlin:トラブル理解ジェネリック
interface A
interface B
class Model() : A, B
私は私のモデルクラスの一覧として一つのパラメータを渡す実装モデルを持っている、コンパイラはモデルAとBであることを理解しかし、私は2つのパラメータを渡すときそのうちの1つはT型(T:A、T:B)で与えられ、コンパイラはそれを理解できません。
protected fun <T> test(givenList: List<T>) where T : A, T : B {
val testList = ArrayList<Model>()
oneParamFunc(testList) // will compile
oneParamFunc(givenList) // will compile
twoParamFunc(givenList, testList) // won't compile (inferred type Any is not a subtype of A)
twoParamFunc<T>(givenList, testList) // won't compile (Required List<T>, Found ArrayList<Model>)
}
protected fun <T> oneParamFunc(list: List<T>) where T : A, T : B { }
protected fun <T> twoParamFunc(oldList: List<T>, newList: List<T>) where T : A, T : B { }
動作させるには何を変更する必要がありますか?