Automatically Generating Type-Safe Builders for Data Classes

I would love to see a automatically generated builder for data classes, but this is a feature which can be easily be implemented using annotation processing so I am not sure if this should necessarily be part of the language itself. Adding a Builder to each data class would double the number of classes required to use data classes which can lead to problems on Android I think.

I think adding an Annotation (@CreateBuilder or something) would just be as effective without the overhead of having Builders for classes which don’t need any. That way you could even possibly add a validation function if you want @CreateBuilder(::validate), which can than be called at runtime.

1 Like