How do I generate getters and setters?
Author: Deron Eriksson
Description: This tutorial describes how to generate getters and setters in Eclipse.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)


EclipseSW makes it very easy to automatically generate getter and setter methods for a JavaSW class. As an example, here we have a class with three member variables: a boolean, an int, and a String.

Eclipse Java Editor

To generate getters and setters, I right-click the editor and go to Source → Generate Getters and Setters.

Selecting 'Generate Getters and Setters'

This brings up the Generate Getters and Setters window. This window allows you to select which getter and setter methods you want to have automatically generated for which member variables. I clicked Select All and clicked OK.

Generate Getters and Setters

Back in the Java editor, we can see that Eclipse has generated getter and setter methods for all the member variables, as expected.

Generated Getters and Setters

As a keyboard shortcut, normally I hit Alt-Shift-S followed by R to bring up the Generate Getters and Setters window.