Skip to content
Advertisement

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“.

Advertisement

Answer

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

Edit: After 5 years, revisiting this topic, would recommend to use lombok that has become industry standard anyway and is also IDE agnostic ==> would work if your team mates use a variety of IDEs. Check out this annotation. You could also include pattern inheritance among classes.

@Builder(toBuilder = true)
// or you could use this for inheritance
@SuperBuilder
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement