CLOVIS
09/12/2024, 8:04 PMkClass
instance for the type of a nullable variable without using reified generics?
fun <T : Any?> classOf(value: T): KClass<T & Any> =
TODO("what to put here??")
such that:
val value: Int? = 5
returns Int::class
?
I can't use value::class
because that's forbidden for nullable valuesGleb Minaev
09/12/2024, 8:19 PMnull
is provided. I mean, what is the `null`'s class? null
has type Nothing?
but it's not a class.Daniel Pitts
09/12/2024, 9:30 PMinline fun <reified T : Any> classOf(value: T?): KClass<out T> = value?.let { it::class } ?: T::class
CLOVIS
09/12/2024, 9:35 PM