Credit Suisse Interview Question
Analystsget that static instance to initialise staticly instead of lazily...
do
private static Singleton instance = new Singleton();
and the getInstance just returns 'instance'. That way you're removing all multithreading concerns from the singleton mechanism.
ummm just look it up?
- Anonymous November 14, 2008public class Singleton {
private static Singleton instance = null;
private Singleton() {}
public Singleton getInstance() {
if (instance == null)
instance = new Singleton();
return instance;
}
}