Java – Create class constructor with fields faster in Eclipse

Consider this class

It has 20 instance variables that need to be initialized. Using getters and setters is too much typing.

We could create a constructor that accepts values for all these variables. Even easier with Eclipse.

Use Eclipse to generate constructors with fields

  1. Right-click anywhere on the source code file.
  2. Choose Source
  3. Then, choose Generate Constructor using Fields…crazyhugejavabean1It will display a windows from which you can select the fields you wish to include in the constructor.14-11-2016-12-08-46-am
  4. Click OK

A constructor will be created.


Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert