Java演示设计模式中的单件模式,设计模式单件,public class
分享于 点击 11309 次 点评:196
Java演示设计模式中的单件模式,设计模式单件,public class
public class SimpleSingleton { private static SimpleSingleton singleInstance = new SimpleSingleton(); //Marking default constructor private //to avoid direct instantiation. private SimpleSingleton() { } //Get instance for class SimpleSingleton public static SimpleSingleton getInstance() { return singleInstance; }}
调用方法
public enum SimpleSingleton { INSTANCE; public void doSomething() { }}//Call the method from Singleton:// http://www.byrx.netSimpleSingleton.INSTANCE.doSomething();
用户点评