given that ```val sClass: KClass = String::class``...
# announcements
s
given that
Copy code
val sClass: KClass = String::class
gives me the
KClass
for
String
, how do I get the
KClass
for
String?
? I tried
Copy code
val nsClass: KClass = String?::class
but that doesn’t compile.
d
There is no
KClass
for
String?
, as
String?
is not a class. If you want to represent
String?
at runtime you need a
KType
. You can use
createType(nullable = true)
for that. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/create-type.html
👍 3
s