Stephan Schroeder
03/10/2020, 12:03 PMval sClass: KClass = String::class
gives me the KClass
for String
, how do I get the KClass
for String?
?
I tried
val nsClass: KClass = String?::class
but that doesn’t compile.diesieben07
03/10/2020, 12:06 PMKClass
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.htmlSackCastellon
03/10/2020, 1:23 PMtypeOf<String?>()
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/type-of.html