I am working on a new Android
project (Java
), and created an Object with a large number of variables. Since I am planning to add getters and setters for all of them, I was wondering: is there a shortcut in Eclipse
for automatically generating the getters and setters in a given class?
-
1Sounds like a stalker to me... I just used to do all Java programming without an IDE, so using Eclipse is still relatively new to me. – Phil Aug 28 '11 at 15:20
-
3@krio - The whole world doesn't use Eclipse for Java dev. I did most of my work in IntelliJ, and found myself asking a lot of questions like this once I started working in Eclipse. – vcsjones Aug 28 '11 at 15:27
-
1@Phil, vcsjones - very true my apologies but check this out, - http://www.google.com.au/#hl=en&cp=25&gs_id=2o&xhr=t&q=create+getters+and+setters+eclipse&pf=p&sclient=psy&biw=1280&bih=680&source=hp&pbx=1&oq=create+getters+and+setter&aq=0&aqi=g1g-v2g-j2&aql=&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.&fp=714149cc57a4f45c - I guess stackoverflow says research is important – TeaCupApp Aug 28 '11 at 16:07
-
2it's fastest way: ctrl+3 g g a s – deldev Jan 22 '15 at 00:21
-
1@Konstantin that just says to avoid using them in the same class, so don't call `this.getCount()`, when you can just reference `this.mCount`. Although it may be a more costly operation, it is a cleaner approach to provide access to variables of other objects via getters and setters. – Phil Feb 03 '15 at 22:45
19 Answers
Bring up the context menu (i.e. right click) in the source code window of the desired class. Then select the Source
submenu; from that menu selecting Generate Getters and Setters...
will cause a wizard window to appear.
Source -> Generate Getters and Setters...
Select the variables you wish to create getters and setters for and click OK
.

- 2,407
- 2
- 12
- 19

- 4,421
- 3
- 20
- 23
-
There is only 'Generate Element Comment', no Getters and Setters. I'm using Eclipse 4.4.0, PDT plugin installed. In meantime this can be used - http://mikeangstadt.name/projects/getter-setter-gen/ . – Xdg Aug 11 '15 at 08:00
-
-
14You can also access this submenu with the keyboard shortcut `SHIFT`+`ALT`+`S`, and then open the Generate Getters and Setters options by pressing `R`. – Rosa Aug 05 '16 at 14:39
-
Funny how my answer here got so popular, but these days I would just use [Lombok](https://projectlombok.org/), as noted by others below. – Hagai Cibulski Aug 22 '18 at 12:53
-
You can also use CMD/CTRL-
and start typing 'get' or 'set' and the proposal window will list any missing getters/setters. Select the one you want to add the implementation. – Kevin May 15 '20 at 16:14
In Eclipse Juno, by default, ALT+SHIFT+S,R opens the getter/setter dialog box. Note you have to press all 4 keys.

- 4,895
- 6
- 31
- 37
-
7You can leave out the SHIFT part and just do ALT + S, R as well. – Jason Wheeler Feb 07 '14 at 23:42
-
2
-
-
-
In Spring Tool Suite 3 --> ALT + SHIFT + S (wait for the menu to open) then press R – skarabel Jul 01 '21 at 09:26
Right click -> Source -> Generate setters and getters
But to make it even more convenient, I always map this to ALT+SHIFT+G from Windows -> Preferences -> General -> Keys

- 4,765
- 8
- 40
- 57

- 588,226
- 146
- 1,060
- 1,140
All the other answers are just focus on the IDE level, these are not the most effective and elegant way to generate getters and setters. If you have tens of attributes, the relevant getters and setters methods will make your class code very verbose.
The best way I ever used to generate getters and setters automatically is using project lombok annotations in your java project, lombok.jar will generate getter and setter method when you compile java code.
You just focus on class attributes/variables naming and definition, lombok will do the rest. This is easy to maintain your code.
For example, if you want to add getter and setter method for age
variable, you just add two lombok annotations:
@Getter @Setter
public int age = 10;
This is equal to code like that:
private int age = 10;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
You can find more details about lombok here: Project Lombok

- 1,537
- 16
- 8
-
2That's it! Thank you very much! Actually, your answer should be on top, since lombok is the only true solution to avoid seeing all the boilerplate Java code one would have to generate or write. Thanks! – Stefan Endrullis Mar 04 '16 at 14:01
-
2Project Lombok (or at least the idea) should be part of Java 11. I use Kotlin for Pojo classes only to escape getter setter generation :/ – Wolf359 Apr 11 '18 at 22:01
-
I agree that using Lombok is a great way to generate getters, setters, equals, hash code, and constructors without having to write a lot of boilerplate code in your class. By using Lombok, you can reduce the amount of repetitive code in your project, making it more concise and easier to maintain. Additionally, Lombok can save you a lot of time and effort, allowing you to focus on the more important aspects of your code, such as business logic and algorithmic design. – Borislav Gizdov May 07 '23 at 23:18
Ways to Generate Getters & Setters -
1) Press Alt+Shift+S, then R
2) Right click -> Source -> Generate Getters & Setters
3) Go to Source menu -> Generate Getters & Setters
4) Go to Windows menu -> Preferences -> General -> Keys (Write Generate Getters & Setters on text field)
5) Click on error bulb of the field -> create getters & setters ...
6) Press Ctrl+3 and write getters & setters on text field then select option Generate Getters & Setters
if Mac OS press Alt+cmd+S then select Getters & Setters

- 1,075
- 15
- 21
-
3I think that 1 it's a bit easier in this way: 1) Press Alt + Shift + S, then R – Paco Abato Sep 29 '15 at 09:24
-
1Pressing Ctrl-3 and directly afterwards typing "getter" is missing from the list. Much easier to remember than specific shortcuts, as this works for every command, view and so on. – Bananeweizen Oct 09 '15 at 05:50
-
Right click-> generate getters and setters does the job well but if you want to create a keyboard shortcut in eclipse in windows, you can follow the following steps:
- Go to Window > Preferences
- Go to General > Keys
- List for "Quick Assist - Create getter/setter for field"
- In the "Binding" textfield below, hold the desired keys (in my case, I use ALT + SHIFT + G)
- Hit Apply and Ok
- Now in your Java editor, select the field you want to create getter/setter methods for and press the shortcut you setup in Step 4. Hit ok in this window to create the methods.
Hope this helps!

- 3,623
- 1
- 25
- 24
Sure.
Use Generate Getters and Setters from the Source menu or the context menu on a selected field or type, or a text selection in a type to open the dialog. The Generate Getters and Setters dialog shows getters and setters for all fields of the selected type. The methods are grouped by the type's fields.
Take a look at the help documentation for more information.

- 138,677
- 31
- 291
- 286
I prefer to create the private field first
private String field;
Eclipse will auto highlight the variable, by positioning cursor over your new variable, press Ctrl + 1. It will then give you the menu to Create getter and setter.
I press Ctrl + 1 because it is a bit more intelligent about what I think you want next.

- 584
- 5
- 13
Yes. Right-click on code and you see a menu pop up; there "Source", "Generate Getters and Setters" and next to it you can see the shortcut, which is Alt+Shift+S and R on my system.
Similarly you can navigate to other submenus in that main menu, by typing the appropriate shortcut you go straight the submenu instead of main context menu, and can then either pick from menu or type another letter to pick from the list.

- 4,311
- 2
- 24
- 28
For All variable ALT+SHIFT+S Then R and for select all Press ALT+A
For Single variable Point cursor on the variable then press CTRL+1 and go for the second option from suggestions

- 176
- 1
- 2
Press Alt+Shift+S+R... and then only select which all fields you have to generate Getters or Setters or both

- 67
- 1
- 2
There is an open source jar available know as Lombok , you just add jar and then annotate your POJO with @Getter & @Setter it will create getters and setters automatically.
Apart from this we can use other features like @ToString ,@EqualsAndHashCode and pretty other cool stuff which removes vanilla code from your application

- 3,475
- 2
- 26
- 49
**In Eclipse Ide
for generating both setters and getters -> alt+shift+s+r then Alt A then click on ok;
for generating only getters ->alt+shift+s+r then press g then click on ok button;
for generating only setters ->alt+shift+s+r then press l then click on ok button;**

- 31
- 1
Right click on the property you want to generate the getter and setters for and choose
Source -> Generate Getters and Setters...

- 13,582
- 13
- 81
- 106
1) Go to Windows->Preferences->General->Keys
2) Select the command
"Generate Getters and Setters"
3) In the Binding
, press the shortcut to like to use (like Alt+Shift+G)
4) Click apply and you are good to go

- 2,664
- 2
- 21
- 18

- 3,929
- 3
- 41
- 51
- Open the class file in Eclipse
- Double click on the class name or highlight it
- Then navigate to Source -> Insert Code
- Click on Getter and Setter
It opens a popup to select the fields for which getter/setter methods to be generated. Select the fields and click on "Generate" button.

- 1,153
- 1
- 9
- 15
Use Project Lombok or better Kotlin for your Pojos.
(Also, to add Kotlin to your resume ;) )
This :
public class BaseVO {
protected Long id;
@Override
public boolean equals(Object obj) {
if (obj == null || id == null)
return false;
if (obj instanceof BaseVO)
return ((BaseVO) obj).getId().equals(id);
return false;
}
@Override
public int hashCode() {
return id == null ? null : id.hashCode();
}
// getter setter here
}
public class Subclass extends BaseVO {
protected String name;
protected String category;
// getter setter here
}
would become this :
open class BaseVO(var id: Long? = null) {
override fun hashCode(): Int {
if (id != null)
return id.hashCode()
return super.hashCode()
}
override fun equals(other: Any?): Boolean {
if (id == null || other == null || other !is BaseVO)
return false
return id.hashCode() == other.id?.hashCode()
}
}
@Suppress("unused")
class Subclass(
var name: String? = null,
var category: String? = null
) : BaseVO()
Or use Kotlin's "data" classes. You end up writing even fewer lines of code.

- 2,620
- 4
- 42
- 62