3 ms·
> kotlin annotations (esp. with addition of KSP) provide good mechanism for compile time code generation. Could you explain this a bit more? I thought kotlin a
by EE84M3i 5y ago
> kotlin annotations (esp. with addition of KSP) provide good mechanism for compile time code generation.
Could you explain this a bit more? I thought kotlin annotations were like Java annotations - additional metadata attached to classes/fields/methods/etc but could not be used by themselves to generate code like a decorator.
- lf-non 5y agoYes, that is precisely what annotations are - a common unified way to attach metadata that various tools can agree upon. KSP [1] is a new addition to the kotlin ecosystem that facilitates cross-platform annotation processing. Various annotation processors can use this metadata to generate code - the generated classes etc. will be separate entities as opposed to direct modifications to targets. Decorators are more powerful in that they can act upon their target directly but also (usually) have runtime overhead - this overhead is one of the reasons why the js proposal had to undergo substantial revisions. [1] https://kotlinlang.org/docs/ksp-overview.html https://kotlinlang.org/docs/ksp-overview.html