2
나는 두 개의 인터페이스코 틀린 : 문제 이해 제네릭
interface A
interface B
class Model() : A, B
내 모델 클래스의 목록과 같은 하나 개의 매개 변수를 전달 구현하는 모델을 가지고, 컴파일러는 모델 A와 B는 것을 이해하지만 두 개의 매개 변수를 통과 할 때 그 중 하나는 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 { }
변경하려면 무엇을 변경해야합니까?