This expression is false. Is there a simple way to...
# getting-started
j
This expression is false. Is there a simple way to check if a class is a boolean class without individually checking both the kotlin and java classes?
Copy code
Boolean::class.java == java.lang.Boolean::class.java // false
g
You can try checking only equality of FQNs:
Copy code
public fun testKClassesEquality(c1: KClass<*>, c2: KClass<*>): Boolean = c1.qualifiedName == c2.qualifiedName
But I am not sure this is enough.
Ah, sorry. I misread the question. I guess you cannot do anything without manually checking both Kotlin and Java classes FQNs.
e
that is basically the difference between
Boolean::class.javaPrimitiveType
and
Boolean::class.javaObjectType
the separation of primitive and reference types in Java is a bit of an annoyance but if you only use Kotlin classes then they're unified
Copy code
Boolean::class == java.lang.Boolean::class.java.kotlin
j
Hm. So the syntax
java.lang.Boolean::class.java.kotlin
lets us go from a Java class to a Kotlin class. But if I'm given a Kotlin class, to convert that to a Java class, I should use
.javaPrimitiveType
?
e
it depends
a Kotlin Boolean may be represented by a primitive Java boolean or a boxed Java Boolean in different circumstances
j
Fair enough. If I just call
Boolean::class.java
does that give the boxed type or primitive?
e
if you call
T::class.java
you get the primitive type if it exists and the reference type otherwise
👍 1
j
Sounds good, thanks