public class Singleton {
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton();
}
private Singleton (){}
public static final Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
- 即使 singleton 类被加载 类也不会创建 , 只有在主动调用getInstance后才会触发内部类的加载 从而创建出Singleton对象的创建
网友评论