Jul 01, 2017 Automatically create constructors, getters, and setters in IntelliJ. This feature is not available right now. Please try again later. Keyboard Shortcut for 'Generate Class' Follow. Dave Schinkel Created November 04, 2013 06:42. Is there a keyboard shortcut for this? Alt+enter on the class name allows you to move it to a new file, or you can use the Move refactor (F6 for IntelliJ scheme, ctrl+R, O for VS) to move the class to a new file, folder, namespace or project. Sep 02, 2014 Useful shortcuts in Eclipse and STS. September 2, 2014. Generate constructor using fields. You can just close it really fast with this key.
IntelliJ IDEA provides multiple ways to generate common code constructs and recurring elements, which helps you increase productivity. These can be either predefined or custom templates that are applied differently based on the context, various wrappers, and automatic pairing of characters.
Additionally, IntelliJ IDEA provides code completion and Emmet support.
From the main menu, select Code | GenerateAlt+Insert to open the popup menu with available constructs that you can generate.
Generate constructors
Intellij Generate Constructor Hotkey Code
IntelliJ IDEA can generate a constructor that initializes specific class fields using values of corresponding arguments.
Generate a constructor for a class
On the Code menu, click GenerateAlt+Insert.
In the Generate popup, click Constructor.
If the class contains fields, select the fields to be initialized by the constructor and click OK.
The following code fragment shows the result of generating a constructor for a class:
Generate delegation methods
IntelliJ IDEA can generate methods that delegate behavior to the fields or methods of your class. This approach makes it possible to give access to the data of a field or method without directly exposing this field or method.
Generate a delegation method for a class
On the Code menu, click GenerateAlt+Insert.
In the Generate popup, click Delegate Methods.
Select the target field or method, and click OK.
Select the desired methods to be delegated and click OK.
The following code fragment shows the result of delegating the get(i) method of the Calendar class inside another class:
Generate equals() and hashCode() methods
The Java super class java.lang.Object provides two methods for comparing objects:
public boolean equals(Object obj)returnstrueif the object passed to it as the argument is equal to the object on which this method is invoked. By default, this means that two objects are stored in the same memory address.public int hashCode()returns the hash code value of the object on which this method is invoked. The hash code must not change during one execution of the application but may change between executions.
It is generally necessary to override the hashCode() method if you override equals() because the contract for hashCode() is that it must produce the same result for objects that are equal. For more information, see the API specification for the Object class.
Generate equals() and hashCode() for a class
From the Code menu, click GenerateAlt+Insert.
In the Generate popup, click equals() and hashCode().
Select a velocity template from the Template list.
You can also click to open the Templates dialog, where you can select an existing template or create a custom template.
Select checkboxes if you want to accept subclasses and use getters during code generation.
Click Next.
Select the fields that should be used to determine equality, and click Next.
Select the fields to use for calculating the hash code value. You can choose only from fields that were selected on the previous step (for determining equality). Click Next.
Select the fields that contain non-null values. This optional step helps the generated code avoid checks for null and thus improves performance. Click Finish.
If the overrides for equals() and hashCode() methods already exist in the class, you will be prompted whether you want to delete them before generating new ones.
The following code fragment shows the result of overriding the equals() and hashCode() methods:
Generate getters and setters
IntelliJ IDEA can generate accessor and mutator methods (getters and setters) for the fields in your classes. Generated methods have only one argument, as required by the JavaBeans API.
The getter and setter method names are generated by IntelliJ IDEA according to your code generation naming preferences.
Generate getters and setters for a class:
On the Code menu, click GenerateAlt+Insert.
In the Generate popup, click one of the following:
Getter to generate accessor methods for getting the current values of class fields.
Setter to generate mutator methods for setting the values of class fields.
Getter and Setter to generate both accessor and mutator methods.
Select the fields to generate getters or setters for and click OK.
You can add a custom getter or setter method by clicking and accessing the Getter/Setter Templates dialog. If a field is not in the list, then the corresponding getter and setter methods are already defined for it.
The following code fragment shows the result of generating the getter and setter methods for a class with one field var:
Note for PHP
This feature is only supported in the Ultimate edition.
The following is only valid when the PHP plugin is installed and enabled.
In the PHP context, getters and setters are generated using the PHP getter/setter file template. By default, as specified in these templates, setters are generated with the set prefix and getters with the set or get prefix according to the inferred field type boolean or con-boolean. The prefix is the value of the ${GET_OR_IS} variable in the default getter template. The default template is configured in the Code tab on the File and Code Templates page of the Settings/Preferences dialog Ctrl+Alt+S.
Generate toString()
The toString() method of the Java super class java.lang.Object returns the string representation of the object. This method can be used to print any object to the standard output, for example, to quickly monitor the execution of your code. By default, toString() returns the name of the class followed by the hash code of the object. You can override it to return the values of the object's fields, for example, which can be more informative for your needs.
Override the toString() method for a class
On the Code menu, click GenerateAlt+Insert.
In the Generate popup, click toString().
Configure the following:
Select the template for generating the
toString()method from the Template list.Select the fields that you want to return in the generated
toString()method. By default, all the available fields are selected. Click Select None to generate atoString()method that returns only the class name.Select the Insert @Override checkbox if necessary.
Click the Settings button to open the toString() Generation Settings dialog. where you can tune the behavior and add custom templates.
Click OK.
If the toString() method is already defined in the class, by default, you will be prompted whether you would like to delete this method before proceeding. You can use the When method already exists group of options in the toString() Generation Settings dialog to change this behavior: either automatically replace existing method or generate a duplicating method.
The following code fragment shows the result of generating the toString() method for a class with several fields defined:
The following code inspections are related to the toString() method:
Class does not override 'toString()' method can be used to identify classes in which the
toString()method is not defined. This inspection uses the exclude settings to ignore classes with fields that are not supposed to be dumped. An additional setting is to exclude certain classes using a regular expression matching their class name. As default, this is used to exclude any exception classes.Field not used in 'toString()' method can be used to identify fields that are not dumped in the
toString()method. For example, if you added new fields to a class, but forgot to add them to thetoString()method. Change the severity of this inspection to show errors as warnings. This will highlight any unused fields in the editor and indicate their location as yellow markers on the scroll bar.
Custom code generation templates

Templates used for generating getters and setters, as well as equals(), hashCode(), and toString() methods are written in the Velocity template language. Although you can't modify predefined templates, you can add your own custom templates to implement necessary behavior.
Intellij Generate Constructor Hotkey Free
IntelliJ IDEA provides the following variables for Velocity templates:
The following variables can be used in templates for generating getters and setters:
Variable | Description |
|---|---|
$java_version | The current version of the Java Runtime Environment (JRE). |
$class | The current class. |
$helper | Provides access to various code generation helper methods. |
$settings | Provides the ability to format names according to the current code style. |
$field | Field for which getter or setter is generated. |
The following variables can be used in templates for generating the toString() method:
Variable | Description |
|---|---|
$java_version | The current version of the Java Runtime Environment (JRE). |
$class | The current class. |
$helper | Provides access to various code generation helper methods. |
$settings | Provides the ability to format names according to the current code style. |
$fields | List of fields in the current class. |
The following variables can be used in templates for generating the equals() method:
Variable | Description |
|---|---|
$java_version | The current version of the Java Runtime Environment (JRE). |
$class | The current class. |
$helper | Provides access to various code generation helper methods. |
$settings | Provides the ability to format names according to the current code style. |
$fields | List of fields in the current class. |
$instanceBaseName | Predefined name of the object on which the |
$baseParamName | Predefined name of the |
$superParamName | The name of the parameter in the |
$checkParameterWithInstanceof | Option passed from the wizard. |
$superHasEquals | Whether the superclass has |
The following variables can be used in templates for generating the hashCode() method:
Variable | Description |
|---|---|
$java_version | The current version of the Java Runtime Environment (JRE). |
$class | The current class. |
$helper | Provides access to various code generation helper methods. |
$settings | Provides the ability to format names according to the current code style. |
$fields | List of fields in the current class. |
$superHasHashCode | Whether the superclass has |
In IntelliJ IDEA Ultimate, the code completion popup is available for custom code generation template variables. Users of IntelliJ IDEA Community Edition can refer to the relevant source code.
IntelliJ IDEA has keyboard shortcuts for most of its commands related to editing, navigation, refactoring, debugging, and other tasks. Memorizing these hotkeys can help you stay more productive by keeping your hands on the keyboard.
Use a keyboard with the English layout. IntelliJ IDEA may not detect some of the shortcuts correctly for other national layouts.
The following table lists some of the most useful shortcuts to learn:
Shortcut | Action |
|---|---|
Double Shift | Find anything related to IntelliJ IDEA or your project and open it, execute it, or jump to it. |
| Ctrl+Shift+A | Find a command and execute it, open a tool window or search for a setting. |
| Alt+Enter | Fix highlighted error or warning, improve or optimize a code construct. |
| F2 Shift+F2 | Jump to the next or previous highlighted error. |
| Ctrl+E | Select a recently opened file from the list. |
| Ctrl+Shift+Enter | Insert any necessary trailing symbols and put the caret where you can start typing the next statement. |
| Ctrl+Alt+L | Reformat the whole file or the selected fragment according to the current code style settings. |
| Ctrl+Shift+Alt+T | Refactor the element under the caret, for example, safe delete, copy, move, rename, and so on. |
| Ctrl+W Ctrl+Shift+W | Increase or decrease the scope of selection according to specific code constructs. |
| Ctrl+/ Ctrl+Shift+/ | Comment out a line or block of code. |
| Ctrl+B | Navigate to the initial declaration of the instantiated class, called method, or field. |
| Alt+F7 | Show all places where a code element is used across your project. |
| Alt+1 | Focus the Project tool window |
| Escape | Focus the editor |
If you are using one of the predefined keymaps for your OS, you can print the default keymap reference card and keep it on your desk to consult it if necessary. This cheat sheet is also available under Help | Keymap Reference.
Choose the right keymap
To view the keymap configuration, open the Settings/Preferences dialog Ctrl+Alt+S and select Keymap.

Enable function keys and check for possible conflicts with global OS shortcuts.
Use a predefined keymap
IntelliJ IDEA automatically selects a predefined keymap based on your environment. Make sure that it matches the OS you are using or select the one that matches shortcuts from another IDE or editor you are used to (for example, Eclipse or NetBeans).
Tune your keymap
You can modify a copy of any predefined keymap to assign your own shortcuts for commands that you use frequently.
Import custom keymap
If you have a customized keymap that you are used to, you can transfer it to your installation.
Learn shortcuts as you work
IntelliJ IDEA provides several possibilities to learn shortcuts:
Find Action is the most important command that enables you to search for commands and settings across all menus and tools.
Press Ctrl+Shift+A and start typing to get a list of suggested actions. Then select the necessary action and press Enter to execute it.
Key Promoter X is a plugin that shows a popup notification with the corresponding keyboard shortcut whenever a command is executed using the mouse. It also suggests creating a shortcut for commands that are executed frequently.
If you are using one of the predefined keymaps for your OS, you can print the default keymap reference card and keep it on your desk to consult it if necessary. This cheat sheet is also available under Help | Keymap Reference.
If an action has a keyboard shortcut associated with it, the shortcut is displayed near the name of the action. To add a shortcut for an action that you use frequently (or if you want to change an existing shortcut), select it and press Alt+Enter.
Use advanced features
You can further improve your productivity with the following useful features:
Intellij Generate Constructor Hotkey Download
If there is a group of actions that you often use, create a quick list to access them using a custom shortcut. For example, you can try using the following predefined quick lists:
Refactor thisCtrl+Shift+Alt+T
VCS OperationsAlt+`
IntelliJ IDEA provides various aids, such as automatically adding paired tags and quotes, and detecting CamelHump words.
When the focus is on a tool window with a tree, list, or table, start typing to see matching items.
Press twice
Many actions in IntelliJ IDEA provide more results when you execute them multiple times. For example, when you invoke basic code completion with Ctrl+Space on a part of a field, parameter, or variable declaration, it suggests names depending on the item type within the current scope. If you invoke it again, it will include classes available through module dependencies. When invoked for the third time in a row, the list of suggestions will include the whole project.
Resize tool windows
You can adjust the size of tool windows without a mouse:
To resize a vertical tool window, use Ctrl+Shift+Left and Ctrl+Shift+Right
To resize a horizontal tool window, use Ctrl+Shift+Up and Ctrl+Shift+Down