OPT.MAF
Make accessor methods for instance fields "final"
Description
This rule flags non-"final" accessor methods for instance fields.
Accessor methods for instance fields should be made "final". This tells the compiler that the method cannot be overridden and thus can be inlined.
Example
package OPT;
class MAF {
public void setSize (int size) {
_size = size;
}
private int _size;
}
Repair
class DAF_fixed {
final public void setSize (int size) {
_size = size;
}
private int _size;
}
Reference
Warren, Nigel. and Bishop, Philip. Java in Practice. Addison-Wesley, 1999, pp 4-5.
|