Singleton模式的两种实现形式
(1)第一种形式
public class AClass { private AClass() { } private static AClass instance = new AClass(); public static AClass getInstance() { return instance; } }
(1)第二种形式
public class AClass { private static AClass instance = null; public static synchronized AClass getInstance() { if (instance == null) instance = new AClass(); return instance; } }