SuperbBuilder - generate Child class builder from Patent builder with abstract Parent

87 views
Skip to first unread message

Robert Sescu

unread,
Feb 13, 2024, 9:10:13 AMFeb 13
to Project Lombok
I am investigating a feature proposal of getting a new Child.builder based on a ParentBuilder. 
I saw that generating ChildBuilder from a Parent instance was discussed before but I couldn't find any discussions about generating a ChildBuilder from a ParentBuilder.
I think this approach would be useful to reduce code duplication in some (my specific) instances.

Something in the direction of generating a $fillValuesFromBuilderIntoBuilder()
Is this something worth pursuing or would it go against lombok guidelines/direction? 

Jan Rieke

unread,
Feb 20, 2024, 7:15:27 AMFeb 20
to project...@googlegroups.com
Hi Robert!

I'm not a member of the lombok team, but I implemented the @SuperBuilder
feature. This feature is already very complicated in two ways: The
generated code is quite long even for small classes and loaded with
generics, and the lombok handler classes are complicated, too.
So from my point of view, every addition that further increases the
complexity should be very-well justified, i.e. it must help a
significant part of lombok users, and cannot easily be replaced by
different means.

Your proposal looks reasonable. However, I doubt it will cross the bar
for both criteria described above:
1. The use-case you describe seems rather rare. Why do you want to
convert an existing ParentBuilder to a ChildBuilder? Could you elaborate
further on possible applications for such a feature?
2. Even if there are use-cases for this, I believe there are easy
workarounds. For instance, you could invert the responsibility of
creating the builder, like this:

ChildBuilder<?,?> builder = Child.builder();
methodThatFillsValuesIntoParentBuilderInstance(builder);
Child child = builder.build();

Even if you really need the other method to create the builder, you
could pass the desired target (builder) class as parameter to that
method, and also use that as return type.

Jan
Reply all
Reply to author
Forward
0 new messages