Home > Java > Generating Getters and Setters in Eclipse

Generating Getters and Setters in Eclipse

I am taking Software Development with Java this semester, so not only am I learning a new language, but a new IDE. Eclipse is one of the most popular of the Java Integrated Development Environments.

eclipse_ide

There is a nice feature in Eclipse that saves a lot typing. It is the Generate Getters and Setters… option on the Source menu.

In the lab we did in class last week there were three main variables.

GenGettersAndSetters1-Eclipse 

 

In Eclipse, go to the Source menu and select Generate Getters and Setters…

GenGettersAndSetters-Eclipse

 

In the Getters and Setters dialog, select which fields you want to create the getter/setter for. In this case, I want all three, so I click the [Select All] button and then click [ok].

GenGettersAndSetters3-Eclipse

 

Magically, all of the getters and setter code is generated for you.

GenGettersAndSetters4-Eclipse

 

Java Lab Source Code 

This works well for straight forward variables. I’m sure it is not the best approach for more advanced situations, but it sure saves a lot of typing.Whew

^..^

Categories: Java
You must be logged in to post a comment.