Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
bgColor#FFCCCC
public static final HashMap&lt;IntegerHashMap<Integer, String&gt;String> hm = new HashMap&lt;IntegerHashMap<Integer, String&gt;String>();

Compliant Solution

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

Code Block
bgColor#ccccff
private static final HashMap&lt;IntegerHashMap<Integer, String&gt;String> hm = new HashMap&lt;IntegerHashMap<Integer, String&gt;String>();

Exceptions

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

One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used a struct instead of a class (if Java supported struct), then it's appropriate to make the class's instance variables public.

Wiki Markup
*EX2:* &quot;"if a class is package-private or is a {{private}} nested class, there is nothing inherently wrong with exposing its data fields - assuming they do an adequate job of describing the abstraction provided by the class. This approach generates less visual clutter than the accessor-method approach, both in the class definition and in the client code that uses it.&quot;" \[[Bloch 08|AA. Java References#Bloch 08]\]. This exception applies to both mutable as well as immutable fields.

...

08. Object Orientation (OBJ)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      08. Object Orientation (OBJ)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      OBJ01-J. Understand how a superclass can affect a subclass