Kotlin Reflection Inter-operating with Java reflection

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any Kotlin Question?