dimanche 27 mars 2016

Kotlin reified generic parameter actual type arguments

Using reified type parameters, one can write an inline function which works with the type parameter through reflection at runtime:

inline fun <reified T: Any> f() {
    val clazz = T::class
    // ...
}

But when f is called with a parameter which is itself a generic class, there seems to be no way to obtain its actual type arguments through T::class:

f<List<Integer>>() // T::class is just kotlin.collections.List

Is there a way to get actual type arguments of a reified generic through reflection?





Aucun commentaire:

Enregistrer un commentaire