0

There's builder pattern which was introduced by Joshua Bloch in him book Effective Java (2nd Edition), you can see description and examples of this pattern here: Too Many Parameters in Java Methods, Part 3: Builder Pattern

Is there any way to make this task done automatically by Eclipse? For example I define only properties, and builder and other methods and constructors will be generated by Eclipse?

Anatoly
  • 5,056
  • 9
  • 62
  • 136

2 Answers2

0

There plugins available that will generate builders for you, Eclipse might even have that built into the IDE these days.

We tried a few, with different results, I never liked them, i felt they were more trouble than they were worth, but thats a personal opinion.

Gavin
  • 1,725
  • 21
  • 34
  • Can you advice something more specific? – Anatoly Nov 15 '15 at 11:09
  • Sorry no, we stopped that experiment a couple of years ago, I don't remember the names of any of the plugins we tried, and if i did I dare say they have all moved on since then. Your best bet is to google for eclipse builder plugin, and evaluate them for which works best in your case. – Gavin Nov 15 '15 at 11:11
0

A better solution than Eclipse code-completion (which tightly-couples your development process to a single IDE) is to use code-generation tools like AutoValue. With AutoValue you define an interface (specifically an abstract class) and it generates an implementation of that interface for you, complete with good default .equals(), .hashCode(), and .toString() implementations.

AutoValue also supports constructing AutoValue instances with a builder pattern using a similar syntax - you define the builder's interface, AutoValue generates the implementation.

The third edition of Effective Java in fact recommends AutoValue.

dimo414
  • 47,227
  • 18
  • 148
  • 244