https://kotlinlang.org logo
a

andries.fc

01/10/2021, 4:24 AM
Does anyone know how construct KClass from Java? The reason I'm asking because I'm integrating a library into my app which uses a factory interface defined in Java, and I need to know from Java if class is in actual fact an Object instance?
t

tieskedh

01/10/2021, 10:46 AM
Haha, late response, but the answer is:
Copy code
kotlin.jvm.JvmClassMappingKt.getKotlinClass(Test.class)
https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#kclass to check if it is an object:
Copy code
JvmClassMappingKt.getKotlinClass(Test.class)
    .getObjectInstance()==null
a

andries.fc

01/11/2021, 6:46 AM
Thanx.
Much appreciated,
3 Views