Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Treat public static fields as constants and declare them as final. Consider the use of enum types in the following example.

Code Block
bgColor#ccccff
public class MyClass {
    public static final int LEFT  = 1;
    public static final int RIGHT = 2;
}

The FuncLoader static instance in the noncompliant example could have been declared as final as below.

Code Block
bgColor#ccccff
...
public static final FuncLoader m_functions;
...

...

Additionally for mutable static state one can define assessor methods and add appropriate security checks. Note that this is a different example and in this case the scope of the static variable has been changed to private.

...