Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference Boolean java class from kotlin?

Tags:

kotlin

As far as I understand Boolean::class.java gives me Boolean.TYPE, but not Boolean.class

like image 789
TpoM6oH Avatar asked Feb 24 '17 13:02

TpoM6oH


People also ask

How do you reference a class in Kotlin Java?

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.

How do I reference a class in Kotlin?

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.

Can I use Java classes in Kotlin?

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.

How do I check my Boolean Kotlin?

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!!


1 Answers

To reference Java primitive and boxed types, use:

  • Boolean::class.javaPrimitiveType (equivalent to Java Boolean.TYPE)

  • Boolean::class.javaObjectType (equivalent to Java Boolean.class)

like image 76
hotkey Avatar answered Oct 20 '22 13:10

hotkey