https://kotlinlang.org logo
#reflect
Title
# reflect
n

nils

10/02/2019, 5:17 PM
Hello, I'm currently working on a framework, which uses reflection to parse and introspect functions. I'm aware that Kotlin applies type erasure to generics during runtime (effectively turning
SomeClass<Type>
into
SomeClass<*>
). However, I'd expect type checks such as the one outlined below to correctly yield
true
. I'd like to ask if the below code snippet is a mistake on my end or if it's related to some kind of bug related to invariances. Thank you.
s

Shane Myrick

10/02/2019, 5:44 PM
I had this same issue when trying to read the classes from arguments. I solved it by getting the class from
jvmErasure
and comparing that instead. That might be a little better than your hacky approach
println(paramType.jvmErasure.isSubclassOf(SomeClass::class))
👍 1
b

bdawg.io

10/04/2019, 11:28 PM
Yeah, the issue above is that
paramKType
is an instance of
KType
describing
SomeClass<*>
, not an instance of
SomeClass
itself
👍 1