mardi 8 mars 2016

How to get a runtime class of a variable in Kotlin?

I want to get a reference to a runtime KClass of a variable. I went through documentation on classes and reflection, but the documentation seems to only explain how to get a static reference to KClass (e.g. String::class for String)

I need a runtime KClass of a variable. This doesn't seem to compile:

fun test(x: Any) {
    val klazz = x::class
} 

How does one get the KClass of x in the example above?





Aucun commentaire:

Enregistrer un commentaire