How can I access `::class` of a nullable reference...
# stdlib
a
How can I access
::class
of a nullable reference? I can do it this way:
nullableVal?.let { it::class }
but I would like to know if there is a shorter version. It's a shame I can't just
nullableVal?::class
instead, like I can with
nullableVal?.javaClass
😅
p
You could write extension property. Smth like this: val Any?.klass : KClass? get() = if (this == null) null else this::class
a
Thanks for the tip. I was wondering if anything similar is already in the stdlib though 🙂
s
Technically, there's
?.javaClass?.kotlin
but that's definitely kinda goofy-looking
👍 1
e