写法一:
public class Singleton {
private Singleton() {
}
private static Singleton so = new Singleton();
public static Singleton getInstance() {
return so;
}
}
写法二:
public class Singleton {
private Singleton() {
}
private static Singleton instance = null;
public static synchronized Singleton getInstance() {
if (instance == null)
instance = new Singleton();
return instance;
}
}