Inter-operating with Java reflection
suggest changeTo 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents