This is very interesting: ``` Class<PersonKotl...
# announcements
p
This is very interesting:
Copy code
Class<PersonKotlin> klass1 = PersonKotlin.class;
KClass<PersonKotlin> kotlinClass1 = JvmClassMappingKt.getKotlinClass(klass1);

Class<PersonJava> klass2 = PersonJava.class;
KClass<PersonKotlin> kotlinClass2 = JvmClassMappingKt.getKotlinClass(klass2);  // error
Although the types of
klass1
and
klass2
are identical the compiler recognizes that I can't call
getKotlinClass
on a Java class. How does it do that?
d
It's not about Java/Kotlin.
JvmClassMappingKt.getKotlinClass(klass2)
returns
KClass<PersonJava>
, and you're assigning it to
KClass<PersonKotlin>
-- it's not "identical types", and they are not assignable to each other.
p
yep, just found out now.. I am dumb.. Thanks!
👌 1
d
Np, that happens 🙂
p
since you are here, so what does it mean to get a KClass of a java class? is it identical to a KClass from a kotlin class?
i am surprised that I can pull constructor parameter names from a Java class using
kotlin-reflect
. I thought those would be only available with the
-parameters
flag.
d
since you are here, so what does it mean to get a KClass of a java class? is it identical to a KClass from a kotlin class?
API-wise, it's the same. Of course, some of methods won't make sense for Java class -- then
KClass
will just fallback on some reasonable defaults (e.g. for
isSealed
it will return
false
)
✅ 1