I have a class: ```val c = Array<Int>::class...
# announcements
c
I have a class:
Copy code
val c = Array<Int>::class
I want to get the parameterized type of c (i.e.
Int
). Is this possible on the JVM?
a
Copy code
Array<Int>::class.java.componentType
👍 1
c
That seems to only work for arrays. Is it possible with, for example, a
Map<String, Int>
?
a
It's not possible. There is type erasure in JVM.
c
I hoped with a reified generic it would be possible.
typeOf<>()
gets me close, but maybe not close enough.
a
It is impossible from the aspect of runtime (JVM).
reified
can only be used on inline function so it has nothing to do with the runtime.
c
This gets me this output...
Copy code
class class kotlin.collections.Map has parameters [class kotlin.reflect.jvm.internal.KTypeParameterImpl]