so use ` x as? y != null`
# getting-started
c
so use
x as? y != null
a
Are you interroping with Java at all? If you just use Kotlin,
is
can compare against nullable types.
Copy code
val x: String? = null
    
    println(x is String) // false
    println(x is String?) // true
c
Hmm thing is I don't have objects, I have an object and a type, but I'm working with
KClass<Any>
instances, which i can't use in both sides of the
is
operator
👍 1
Came up with this in case you'll need it 😄 Edit: That was wrong, better way
Copy code
infix fun <T : Any> KClass<out Any>.instanceof(clazz: KClass<T>): Boolean {
    return try {
        this as T
        true
    } catch (e: ClassCastException) {
        false
    }
}
m
Might as well make that reified