Generating field accessor methods

When you add a field to a class with the Create Field SmartGuide, you can choose to generate accessor ("get and set") methods for the field.

To open the Create Field SmartGuide, click the New Field toolbar button newfield.gif (1029 bytes).  After defining the field, enable the Access with getter and setter methods check box, and set the appropriate options.

You also can add accessors to existing fields by doing the following things: 

  1. In your Workspace, select a class that contains fields that you want to generate accessors for.
  2. From the Selected menu, select Generate > Accessors. A Generating accessors dialog box opens.
  3. Select the fields that you want to create getter and setter methods for.
  4. Complete the rest of the options in the dialog box.
  5. Click OK.

VisualAge for Java will generate the accessors.

ngrelt.gif (466 bytes)
Creating a field