https://kotlinlang.org logo
Title
c

ClaudiuB

01/17/2018, 7:06 PM
so use
x as? y != null
a

adam-mcneilly

01/17/2018, 7:08 PM
Are you interroping with Java at all? If you just use Kotlin,
is
can compare against nullable types.
val x: String? = null
    
    println(x is String) // false
    println(x is String?) // true
c

ClaudiuB

01/17/2018, 7:11 PM
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
infix fun <T : Any> KClass<out Any>.instanceof(clazz: KClass<T>): Boolean {
    return try {
        this as T
        true
    } catch (e: ClassCastException) {
        false
    }
}
m

Max Russek

01/18/2018, 2:05 AM
Might as well make that reified