Shortcut to create getter/setters in NetBeans

By | 28 February, 2014

So, if you are in a hurry to create a super ninja class and dont have time to waste on stupid type-all-the-characters actions to create basic getter/setters, in NetBeans you can do this:

After defining your attributes, for example:

private String name;
private int age;

You can go to the menu “Refactor” (top menu) and choose “Encapsulate Fields…”, or the context menu (right mouse button) and chose the same (Refactor->Encapsulate Fields…”.

Choose the attributes for which you want to create getter/setters, chose your options (self explanatory) and click “Refactor”. Presto. Simple basic fast getter/setters. Go thank me.

UPDATE: Another way of achieving this (and other auto code inserting) is by clicking your right mouse button, select “Insert Code..” and go crazy with what’s in there.