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


Page:    1 2 >

EclipseSW makes it easy to generate constructors. As an example, I'll use the Test class below, which contains three member variables: aBooleanVariable, anIntVariable, and aStringVariable.

Eclipse Java Editor

To generate a constructor, I right-click the class in the editor and select Source → Generate Constructor using Fields.

Selecting 'Generate Constructor using Fields'

In the 'Generate Constructor using Fields' window, I select to generate a constructor using all three fields in the specified order, and I decide to create a public constructor. I click OK.

Generate Constructor using Fields

Eclipse automatically generates a constructor for my class featuring three parameters to set the three member variables.

Generated Constructor

(Continued on page 2)

Page:    1 2 >