Generating Constructors
On this page:
Introduction
Constructor generator makes it possible to create constructors with arguments. The value of these arguments are assigned to the field variables.
The generated constructors are inserted at the points defined in the Order of Members section of the Code Style settings. By default, the code generator places constructors after the fields.
Generating a constructor
To generate a constructor
- On the main menu, choose . Alternatively, right-click the editor and choose Generate on the context menu, or use Alt+Insert keyboard shortcut.
- In the pop-up list that is displayed in the editor, select Constructor option.
- If the class in question contains fields, IntelliJ IDEA suggests you to select the fields to be initialized by constructor. In the Choose Fields to Initialize by Constructor dialog, select the desired fields.
- Click OK.
Example
public class MyClass {
int aInteger;
double bDouble;
public MyClass(int myAIntegerParam, double myBDoubleParam) {
aInteger = myAIntegerParam;
bDouble = myBDoubleParam;
}
}
See Also
Reference:
Last modified: 18 July 2017