public class Single {
private int id;
private Single(){
System.out.println("init.....");
}
private static class FooHolder {
static final Single foo = new Single();
static {
foo.id=3;
System.out.println("init id................");
}
}
public static Single getFoo() {
return FooHolder.foo;
}
public static void main(String[] args) throws Exception {
Class.forName("Single");
System.out.println("---------------");
Single s=Single.getFoo();
System.out.println("1111111111111111111111111");
}
}
单例模式静态内部类实现
901

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



