Java Reference
In-Depth Information
Figure 3.18
Constructors are trivial to write, so IDEA can do it
for you. The constructor generator needs to know
which fields are instantiated by the constructor,
and it uses this window to let you pick them.
The generated constructor's parameters will appear in the same order
that they appear in the constructor dialog. If you want to reorder them
later, you can use the Change Method Signature refactoring discussed
in chapter 9.
TIP
In the example shown in figure 3.18, we've selected one field to serve as our argu-
ment. The code generated by this selection is as follows:
public CurrencyExchangeBean(Currency startingCurrency) {
this.startingCurrency = startingCurrency;
}
If you have defined parameter prefix/suffixes in your Code Style set-
tings, the generated parameter names appear with the specified prefix
and/or suffix.
TIP
3.7.2
Generating accessor and mutator methods
Like the constructor generator, the accessor and mutator generators work against
your existing fields. Accessor and mutator methods are used to provide users of
the class with the ability to get and set the values of internal fields without having
direct access to the fields. Using accessors and mutators instead of direct field
access is desirable because it makes it possible to change the class's implementa-
tion without affecting its public API . Some tools, such as reflection, JSP , and the
JavaBeans API , are based around the getter/setter model and expect a standard
method signature. For example, to get and set a property of type double named
rate , IDEA generates the following methods:
public double getRate() {
return rate;
}
 
 
 
Search WWH ::




Custom Search