Versions Compared

Key

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

...

Code Block
bgColor#ccccff
public class Widget {
  private int total;
  void add (someType someParameter) {
    total++;
    // ...
  }
  void remove (someType someParameter) {
    total--;
    // ...
  }
  public int getTotal () {
    return total;
  }
}

Noncompliant Code Example

This noncompliant code example shows a mutable hash map with public accessibility.

Code Block
bgColor#FFCCCC

public static final HashMap<Integer, String> hm = new HashMap<Integer, String>();

Compliant Solution

Mutable data members that are static must always be declared private.

Code Block
bgColor#ccccff

private static final HashMap<Integer, String> hm = new HashMap<Integer, String>();

Exceptions

Wiki Markup
*EX1:* According to Sun's Code Conventions document \[[Conventions 09|AA. Java References#Conventions 09]\]:

...