Kotlin Reflection edit

Inter-operating with Java reflection

To obtain a Java’s Class object from Kotlin’s KClass use the .java extension property:

val stringKClass: KClass<String> = String::class
val c1: Class<String> = stringKClass.java

val c2: Class<MyClass> = MyClass::class.java

The latter example will be optimized by the compiler to not allocate an intermediate KClass instance.

Feedback about page:

Optional: your email if you want me to get back to you:

  ↑ ↓ to navigate     ↵ to select     Esc to close