Hello! I tried convincing my team to start using s...
# kontributors
u
Hello! I tried convincing my team to start using some Kotlin in our Java projects. We decided on using Kotlin data classes but ran directly into a problem: our classes contain many fields, and in order to instantiate them (from Java) we had to use monstrous constructors, wheres before that we used Lombok builders. I investigated some time on trying to find a way to create builders for data classes but couldn't find any. So now I wonder: wouldn't it be great if data classes contained builders by default? That would certainly increase interoperability with Java. Oh and I'm posting it here because I thought maybe I'd try to implement it myself.
s
Named arguments will probably overcome the use of builders. Because in builder you can create a objects easily by setting the required params only. The same thing can be done with the named arguments.
u
Sadly, Java does not yet support named arguments
s
Ohh. You are instantiating it from java.
That would be great for interoperability with java. How you are going to implement it. Any ideas?
u
But right now I'm trying to find tests for data classe creation in the source code. Not too easy to find stuff here! Is there any overview or guidelines I can look at?
s
Great. you can do one thing, create a library same as Autovalue to generate builder classes for kotlin using annotations with the help of KotlinPoet. It will be helpful for all the developers with the ease of dependency setup.
g
For java we create special builder functions in Kotlin (use named and default arguments on Kotlin side)