恶汉式
public class EagerSingleton { PRivate static final EagerSingleton instance = new EagerSingleton(); private EagerSingleton() { } public static EagerSingleton getInstance() { return instance; } }懒汉式
public class LazySingleton { private static LazySingleton instance = null; private LazySingleton() { } public synchronized static LazySingleton getInstance() { if(instance == null){ instance = new LazySingleton(); } return instance; } }新闻热点
疑难解答