...
Code Block |
---|
|
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 |
---|
|
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 |
---|
|
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]\]: |
...