@Builder and inheritance

3,264 views
Skip to first unread message

flexguse

unread,
Jan 28, 2014, 11:53:14 AM1/28/14
to project...@googlegroups.com
Hi,

I had my first day with Lombok and I really liked it ;) Just found the @Builder annotation and I'm quite exited.

But unfortunately in my this extremely useful feature does not work properly. I have an abstract class (AbstractEntities) which is the parent of all my entities. In AbstractEntity there is an required attribute "myRequiredAttribute". If I now put the @Builder annotation to my entities the Builder has no method the set "myRequiredAttribute".

To you see any chance to let @Builder not only inspect the current entity but also the parent entities? Or maybe the inspection is done until @MappedSuperclass is found?

Regards,
Christoph

Martin Grajcar

unread,
Jan 28, 2014, 12:27:39 PM1/28/14
to project...@googlegroups.com
IIUYC, this is not a problem of the Builder, it's a problem of the generated constructor. Builder works with any static method or constructor and placing @Builder on the class is just a shortcut generating the @AllArgsConstructor. The Builder then handles all the arguments.




--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

flexguse

unread,
Jan 29, 2014, 5:01:01 AM1/29/14
to project...@googlegroups.com
Hi Maaartin,

thanks for your reply.

If there is no quick solution available, I have to use something different to create my Builders ;)

Regards,
Christoph

Vyacheslav Blinov

unread,
Jan 29, 2014, 5:05:27 AM1/29/14
to project...@googlegroups.com
Hi,

As a workaround for the issue with @Builder + @AllArgsContstructor on subclass, you can create your own constructor with all the parameters you need and annotate it with @Builder.

Regards,
Vyacheslav

Martin Grajcar

unread,
Jan 29, 2014, 6:13:25 AM1/29/14
to project...@googlegroups.com
Yes, that's what I've meant (but forgot to say explicitly). It still saves most of the boilerplate.

flexguse

unread,
Feb 3, 2014, 5:42:10 AM2/3/14
to project...@googlegroups.com
Hi Maaartin, hi Vyacheslav,

thanks for your suggestions, I tried them out.

I think in my case it is better to use for the builders something else than Lombok and not to have to cope with own constructors.

Regards,
Christoph


Arnaud Deprez

unread,
Mar 26, 2015, 5:11:43 PM3/26/15
to project...@googlegroups.com
Hi guys !

There are still a lot of +1 for this issue about @Builder annotation and inheritance here : https://github.com/peichhorn/lombok-pg/issues/78#issuecomment-69006068
There are also some propositions.

I thinks it can be a good idea to investigate on it.

Rgds
Reply all
Reply to author
Forward
0 new messages