单例模式-1
例模式 (Singleton),也叫单子模式 ,是一种常用的public class Singleton { private static Singleton INSTANCE = new Singleton(); // Private constructor suppresses // default public constructor private Singleton() {} public static Singleton getInstance() { return INSTANCE; } }
?
?
?
?? ? ?
?
public class Singleton { private static Singleton INSTANCE = null; // Private constructor suppresses // default public constructor private Singleton() {} public synchronized static Singleton getInstance() { if(INSTANCE==null) INSTANCE=new Singleton(); return INSTANCE; } } ? ? ? ? ? ?
?