I posted in <#CQ3GFJTU1|language-evolution> and wa...
# kotlin-native
c
I posted in #language-evolution and was told more Native team might see this here: I have interest in K/N reflection. If I were interested in doing work to add support for it, what would be involved in that? Is it currently blocked by technical limitations, is it not desired, or would this kind of thing be practical?
Some things may have changed since this was posted, but this was @elizarov's stance on the matter back in 2017.
For the record, I agree with this stance—many of the systems that would seem to require reflection can actually be implemented via compiler intrinsics (such as typeOf).
c
TL;DR: I can write an extension if there isn't interest, figured I'd ask In my specific use case, I could possibly rewrite the system to use passed function references, but it would add a lot of undesired complexity, and reduce the flexibility. From a more abstract viewpoint, I support adding reflection for increased feature-parity, and to allow more projects that work on JVM to be 'trivially' multiplatform. I understand not wanting to increase binary size, though I suspect that in most situations, the data could be elided (KClass isn't referenced / a flag is added) and for many code bases, the added size would be negligible. If the team has no interest, my alternative is to write a compiler extension that emits the necessary static data / KClass extensions, I just figured that if I was going to go through the effort of it, I should see if it was desired in base.
e
We don’t plan to support open-world reflection in Kotlin/Native. Since JVM is moving away from suporting it, too, I don’t think this position will be changing in a foreseable future. All use-cases for this kind of reflection that we are aware of are well covered by source-code generators and compiler plugins. We do invest our efforts into stabilizing compiler plugins API in the future. See also KSP that was recently announced by Google.
c
👍 thanks for the quick response, I'll be going for a compiler plugin then probably