Home
Constructor using fields
This option adds a constructor that initializes any or all of the defined fields of the currently opened type. Right-click anywhere in the Java editor and select Source Æ Add Constructors using Fields. Select the fields which you want to initialize with the constructor and click OK (Figure | 56).
![]()
Figure 8-56 Generate Constructor using Fields dialog
Example | 9 shows the constructor code which would be generate with the settings shown in Figure | 56.
Example 8-9 Generated constructor code
public Customer(String ssn, String title, String firstName, String lastName,ArrayList<Account> accounts) {this.ssn = ssn;this.title = title;this.firstName = firstName;this.lastName = lastName;this.accounts = accounts;}
![]()
ibm.com/redbooks