下边代码内容是关于Java演示设计模式中的单件模式的代码,应该是对小伙伴们有所用处。
public class SimpleSingleton {
private static SimpleSingleton singleInstance = new SimpleSingleton();
private SimpleSingleton() {
}
public static SimpleSingleton getInstance() {
return singleInstance;
}
}
调用方法
public enum SimpleSingleton {
INSTANCE;
public void doSomething() {
}
}
SimpleSingleton.INSTANCE.doSomething();
转载于:https://blog.51cto.com/14141172/2348784