robstoll
06/17/2019, 4:47 PMinline fun <reified T> foo() = T::class.qualifiedName
be disallowed if inline fun <reified T> foo() = T::class
is?Shawn
06/17/2019, 4:50 PMinline fun <reified T : Any> foo(): KClass<T> = T::class
is what you want because KClass<T>
is explicitly bounded to Any
robstoll
06/17/2019, 4:51 PMinline fun <reified T> foo() = T::class.qualifiedName
or to ask differently what is the type of T::class
and how can I use it in other code 😄Shawn
06/17/2019, 4:52 PMString?
T
in the return typeT::class
is KClass<T>
robstoll
06/17/2019, 4:54 PMKClass<T>
requires T
to have an upper bound of Any
-- it's unsafe to ignore that no?inline fun <reified T> foo() : String? {
val a: KClass<T> = T::class
return a.qualifiedName
}
Does not compilefoo<Int?>()
returns <http://kotlin.Int|kotlin.Int>
, no mentioning of the nullable partShawn
06/17/2019, 5:01 PMInt?::class
won’t compilerobstoll
06/17/2019, 5:02 PMShawn
06/17/2019, 5:10 PM