mbonnin
10/26/2019, 12:30 PMfun <T> foo(aClass: java.lang.Class<T>): MutableList<T> {
return mutableListOf()
}
inline fun <reified T:Any> bar(t: T): MutableList<T> {
// fails here: expected: MutableList<T>, found: MutableList<out T>
return foo(t::class.java)
}
karelpeeters
10/26/2019, 1:06 PMt
could have a subtype of T
, and so t::class.java
could be a subclass of Class<T>
and a MutableList
is invariant. The only thing you can do is make bar
return MutableList<out T>
which is correct.mbonnin
10/26/2019, 1:16 PMright, thanks !could have a subtype oft
T