IntelliJ IDEA 13.1.0 Web Help

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.

To generate a constructor
  1. On the main menu, choose Code | Generate. Alternatively, right-click the editor and choose Generate on the context menu, or use or or or or keyboard shortcut.
  2. In the pop-up list that is displayed in the editor, select Constructor option.
  3. 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.


    Use and keys for multiple selection.

  4. Click OK.


      public class MyClass {
    int aInteger;
    double bDouble;

    public MyClass(int myAIntegerParam, double myBDoubleParam) {
        aInteger = myAIntegerParam;
        bDouble = myBDoubleParam;

See Also


Web Resources: