Sam Garfinkel
08/22/2019, 2:47 PMType?
), but it would be kind of cool to replace those with as?
directly.diesieben07
08/22/2019, 2:57 PMas
will only check actual types. You can do something like this though to make it explicit:
interface IsDisguise {
fun <T : Any> unpack(cls: KClass<T>): T?
}
inline fun <reified R : Any> Any?.unpack(): R? {
return this as? R ?: (this as? IsDisguise)?.unpack(R::class)
}
Sam Garfinkel
08/22/2019, 3:01 PMLeoColman
08/22/2019, 4:00 PMas
and is
overloads?diesieben07
08/23/2019, 7:05 AMas
and is
use to a method call which does some "magic" instead of just an instanceof
or cast
JVM instruction. That would certainly come with performance problemsdiesieben07
08/23/2019, 7:06 AMis
and as