Could someone let me know the places where we need to use private static object in java?
the places i mean is about the reasons behind in using them or the use cases where we need to use them.
Thanks, Kathir
Another common use is for the Singleton Pattern: http://en.wikipedia.org/wiki/Singleton_pattern
public class Singleton {
private static final Singleton instance = new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return instance;
}
}
One common example is for logger.
private final static Logger LOGGER = Logger.getLogger(Something.class);
Or even for constants local to the class.
example from JDK:
public class HashSet<E>
extends AbstractSet<E>
implements Set<E>, Cloneable, java.io.Serializable
{
static final long serialVersionUID = -5024744406713321676L;
private transient HashMap<E,Object> map;
// Dummy value to associate with an Object in the backing Map
private static final Object PRESENT = new Object();
...