我没有明白为什么实例变量没有初始化就有null值。。。完整代码在下面:
class lSingle{ private lSingle(){} private static lSingle s; public static lSingle getInstance() { System.out.println("111111"+s); if(s==null) { synchronized(lSingle .class) {if(s==null) s=new lSingle(); } } return s; } } class lSingleDemo { public static void main(String[] args) { lSingle ls = lSingle.getInstance(); System.out.println(ls); } } out: 111111null SingleTest.lSingle@24c98b07 |