public class Demo {
private static Type instance;
private static class TypeHolder{
pulbic static Type type=new Type();
}
public getInstance(){
return TypeHolder.type;
}
}
本文介绍了一种使用静态内部类来实现单例模式的方法。通过这种方式,可以在不增加同步开销的情况下延迟实例化单例对象。
public class Demo {
private static Type instance;
private static class TypeHolder{
pulbic static Type type=new Type();
}
public getInstance(){
return TypeHolder.type;
}
}

被折叠的 条评论
为什么被折叠?