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 Listing on GitHub

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

^..^

Advertisement

Posted on February 7, 2010, in Java. Bookmark the permalink. 1 Comment.

Leave a Reply

Please log in using one of these methods to post your comment:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.