- 手写单例模式
public class Singleton {
private Singleton() {
}
private enum SingletonHolder {
HOLDER;
private Singleton singleton;
SingletonHolder() {
singleton = new Singleton();
}
}
public static Singleton getInstance() {
return SingletonHolder.HOLDER.singleton;
}
}
网友评论