Thread
#reflect
    nils

    nils

    2 years ago
    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.
    Shane Myrick

    Shane Myrick

    2 years ago
    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))
    b

    bdawg.io

    2 years ago
    Yeah, the issue above is that
    paramKType
    is an instance of
    KType
    describing
    SomeClass<*>
    , not an instance of
    SomeClass
    itself