PB.AUO
Avoid using an object to access "static" fields or methods
Description
This rule flags any "static" field or method that is accessed through an object.
All "static" members should be referenced through a class name.
Example
package PB;
class AUO {
static void staticMethod () {}
void method () {}
public static void main (String[] args) {
AUO object = new AUO ();
object.staticMethod (); // Violation
object.method ();
}
}
Repair
Access "static" methods and fields through the "class".
class AUO_fixed {
// ...
public static void main (String[] args) {
AUO object = new AUO ();
AUO.staticMethod ();
object.method ();
}
}
|