Auto generated extension functions & properties


This question is inspired by Mapping immutable data class instance.

I’d like to generate my special functions like ‘copy’ or ‘componentN’ at data classes. Does Kotlin provides some official means to do that or to simplify such a task?

If not, please give me a hint, how it could be done in a best way.

Ideally I’ like to do that in such a way that for the programmer-user it looked like as just importing some package (and may be some annotation, but better without) and voila we have our classes extended.


Probably the best way to go would be . Overall it is not very well-documented, but should work fine. It doesn’t by itself provide extra help for processing the annotations though (there is an example of how to use it at