What is the eclipse shortcut for auto-generating a default and field constructor?

JavaEclipseKeyboard Shortcuts

Java Problem Overview


I had a look at: Eclipse-Shortcuts, but I found nothing for generating a constructor.

Whats the shortcut for generating a standard constructor?

Java Solutions


Solution 1 - Java

Type the first letter of your class, then press Ctrl+Space, Eclipse will list suggestions within a combobox. The topmost suggestion is the default constructor. Press Enter, it will be done. (I'm using Eclipse Juno and it works.)

Solution 2 - Java

Alt+Shift+s and then o opens the Generate Constructor using Fields dialog.

Solution 3 - Java

Goto Source ---> Generate constructor using Fields

Under Source Title bar, select the Generate constructor using Fields option.

Or

Ctrl+Space which displays the various suggestions possible, from there you can go for the default contructor.

Solution 4 - Java

Ways to Generate default Constructor -

  1. Press Ctl + Space

Ways to Generate field Constructor -

  1. Press Alt + Shift + S + O
  2. Right click -> Source -> Generate Constructor using field
  3. Go to Source menu -> Generate Constructor using field
  4. Go to Windows menu -> Preferences -> General -> Keys (Write Generate Constructor using field on text field)

Solution 5 - Java

When you hit CTRL-SPACE inside your class definition, you will see a drop down. First option is your Constructor.

Solution 6 - Java

For Mac Users it is

Option + Command(⌘) + S or

Command(⌘) + Option + S will open the pop up.

Solution 7 - Java

Or you could type Ctrl + 3 and type GCUF, what means. Generate Constructor Using Field. Do almost the same to generate getters and setters: Type Ctrl + 3 and type GGAS, what means, Generate Getters And Setters

Solution 8 - Java

There are several ways you can follow.

  1. easiest:- put the cursor inside the class and Ctrl + Space then click Enter (because the first option of the list given by ctrl+ space is contructor)

  2. Ctrl + 3 type "constr" . hit Enter. you'll get the dialog box of generate constructor. here you can select whether you want the parameter or not. select and hit Enter

  3. Click Alt + Shift + s then click o You will get the same dialog box mentioned in the above (2). Do your selection. hit Enter

Solution 9 - Java

I think CTRL + 3 is great.

GCFS - generate constructors from a superclass. GCUF - generate constructor using fields. GGAS - generate getters and setters.

Solution 10 - Java

I think shortcut key to generate Constructors is outdated. Alt+Shift+s and then press A opens the Generate Constructor using Fields dialog

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmaximusView Question on Stackoverflow
Solution 1 - JavaJuvanisView Answer on Stackoverflow
Solution 2 - JavaLuGoView Answer on Stackoverflow
Solution 3 - JavaKumar Vivek MitraView Answer on Stackoverflow
Solution 4 - JavaDeepak GuptaView Answer on Stackoverflow
Solution 5 - JavaFrankView Answer on Stackoverflow
Solution 6 - JavaMuhammad NayabView Answer on Stackoverflow
Solution 7 - JavaRolmer Telis de OliveiraView Answer on Stackoverflow
Solution 8 - JavaRavinda LakshanView Answer on Stackoverflow
Solution 9 - Javairm DView Answer on Stackoverflow
Solution 10 - JavaASharma7View Answer on Stackoverflow