2
我试图从通用的方法如何投票列表<<MyClass>至列表<T>?
代码波纹管返回一个特定的列表:
val list: List<Animal> = listOf(Animal(1), Animal(2), Animal(7))
val storage = object : Storage {
override fun <T> fetch(clazz: Class<T>): List<T> {
if(clazz is Animal::class.java){
return list
}
throw RuntimeException()
}
}
但我有一个例外:
Error:(14, 20) Kotlin: Type mismatch: inferred type is kotlin.collections.List<polar.QueryTest.Animal> but kotlin.collections.List<T> was expected
如何正确地返回列表?