IntelliJ IDEA 14.0.0 Web Help

Generating Constructors

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 Alt+Insert 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.
  4. Click OK.

Example

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

See Also

Reference:

Web Resources:

Last modified: 12 November 2014
comments powered by Disqus