As far as I understand Boolean::class.java
gives me Boolean.TYPE
, but not Boolean.class
According to the Kotlin documentation, when we create an object using any class type as below the reference type will be type of KClass. Kotlin class reference is not the same as a Java class reference. To get a Java class reference, use the . java property on a KClass instance.
To obtain the reference to a statically known Kotlin class, you can use the class literal syntax: val c = MyClass::class //The reference is a value of type KClass. Note that a Kotlin class reference is not the same as a Java class reference.
In fact, Kotlin code is fully compatible with Java code. Therefore, you can be able to use both the Java and Kotlin languages in a single project due to Interoperability.
A straightforward approach to checking nullable Boolean variables in if statements is comparing the variable with the expected value. The check above routes the processing to two branches: the “true” and the “false or null” case. Comparing to “b != null && b!!
To reference Java primitive and boxed types, use:
Boolean::class.javaPrimitiveType
(equivalent to Java Boolean.TYPE
)
Boolean::class.javaObjectType
(equivalent to Java Boolean.class
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With