Hi all, just a curiosity. Why the type of `String:...
# announcements
m
Hi all, just a curiosity. Why the type of
String::class
is
KClass<String>
while the type of
"Hello"::class
is
KClass<out String>
? This means that what
"Hello"::class
returns is a
KClass<T>
where
T
is a subtype of
String
. But
String
is final and it doesn't have subtypes. 🤔
k
Typing is just not that smart.
m
It's also funny that
Copy code
val jClazz: Class<String> = String.javaClass
doesn't compile because it's expecting a
Class<String>
while
String.javaClass
is a
Class<String.Companion>
. When you remove the explicit type and get
Copy code
val jClazz = String.javaClass
it compiles and the inferred type is....
Class<String>
.
😆 2