https://kotlinlang.org logo
#reflect
Title
# reflect
m

marcinmoskala

04/06/2020, 3:18 PM
Started playing with kapt, but cannot get Kotlin Reflection from
RoundEnvironment
. Got
TypeElement
but don’t have any idea how to make KClass out of that. Any ideas?
d

diesieben07

04/07/2020, 7:25 AM
You can't,
KClass
is a runtime representation. But during kapt the code is still being compiled, there is no runtime. What you can do is extract the
@kotlin.Metadata
annotation from the classes and then use
kotlinx-metadata-jvm
to parse the Kotlin-specific information. Its not as easy to use as just
KClass
, but if you absolutely need some Kotlin-specific information out of the class you can use it. https://github.com/JetBrains/kotlin/tree/master/libraries/kotlinx-metadata/jvm
m

marcinmoskala

04/07/2020, 5:38 PM
Thanks
2 Views