public class TestSingle {
private static TestSingle s = null;
private TestSingle(){}
public static TestSingle getInstance(){
if(s == null){
synchronized(TestSingle.class){
if (s == null)
s = new TestSingle();
}
}
return s;
}
}
在静态的getInstance方法中使用s = new TestSingle(),而TestSingle()的构造函数不是非静态的吗,这样为什么不报错? |
|