Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically create builder for class in Eclipse

Is there a way to use an automatic builder to create builder (Joshua Bloch's Builder Pattern) for classes in Eclipse? For example an option in the menu, a plugin or something else. I could not find anything under "Refactor".

like image 923
hasanghaforian Avatar asked Apr 07 '15 14:04

hasanghaforian


Video Answer


2 Answers

You may want to look at lombok annotations to generate builders without the boiler plate code. For example:

@Builder public class MyPojo {     private String name; }  MyPojoBuilder.builder().name("yourame").build(); 

The limitation is that this doesn't seem to work with abstract classes.

like image 190
jaco Avatar answered Oct 08 '22 20:10

jaco


Maybe I am late to the party.

Eclipse on its own does not provide a way to generate code to support builder pattern. However it can be extended through plugins to enhance the functionality.

There is this plugin that I use this:

https://github.com/henningjensen/bpep

like image 37
Khanna111 Avatar answered Oct 08 '22 22:10

Khanna111