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?
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.
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
.
In Eclipse Juno, by default, ALT+SHIFT+S,R opens the getter/setter dialog box. Note you have to press all 4 keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With