Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to automatically generate getters and setters in Eclipse?

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?

like image 744
Phil Avatar asked Aug 28 '11 14:08

Phil


People also ask

Can Eclipse generate getters and setters?

To generate getters and setters, do the following: Create the fields you want in the class then press Alt+Shift+S, R. A dialog will pop up allowing you to choose the fields you want to generate getters and setters for. Click Select All to create getters/setters for all fields.


2 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.

like image 156
Hagai Cibulski Avatar answered Sep 21 '22 07:09

Hagai Cibulski


In Eclipse Juno, by default, ALT+SHIFT+S,R opens the getter/setter dialog box. Note you have to press all 4 keys.

like image 31
RoboAlex Avatar answered Sep 23 '22 07:09

RoboAlex