Thread
#reflect
    a

    albertgao

    4 years ago
    I got a
    param.type === nz.salect.objJSON.JVMBranchTest.MenuObject?
    where
    param:KParameter
    . But when I tried to get the class definition from
    param.type
    via
    param.type::class
    . Instead of getting the above
    MenuObject
    , I get a
    class kotlin.reflect.jvm.internal.KTypeImpl
    . How to get my own class , I mean, a
    KClass
    ? Thanks 🙂
    Jesus, just need to cast:
    param.type.classifier as KClass<*>
    udalov

    udalov

    4 years ago
    Depending on your use case,
    param.type.jvmErasure
    might be more helpful
    a

    albertgao

    4 years ago
    @udalov What’s the differences between the
    jvmErasure
    and
    classifier
    ?
    udalov

    udalov

    4 years ago
    jvmErasure
    returns the class that represents the erasure of the given type on JVM. For normal classes, this is always simply that class. For generic type parameters, this is the erasure of the generic bound, or
    Any
    if there's no bound. For example, erasure of a simple type like
    String
    is class
    String
    itself. Erasure of a type
    List<String>
    is class
    List
    . Erasure of
    T
    in
    fun <T> foo() {}
    is class
    Any
    . Erasure of
    Y
    in
    fun <X : Set<String>, Y : X> bar() {}
    is class
    Set
    .