| 本帖最后由 想做开发 于 2014-8-28 10:05 编辑 
 编写一个延迟加载的单例设计模式时出现这个异常Exception in thread "main" java.lang.StackOverflowError。查了一下说是栈溢出问题。有懂的可以解释一下么。
 复制代码package com.itheima;
/**
 * 7、 编写一个延迟加载的单例设计模式。
 * @author
 *
 */
class single{
        
        private single(){}
        private static single s=null;
        public static single getInstance(){
             if(s==null){
                 synchronized(single.class)//同步锁
                   {
                        if (s==null){
                                s=single.getInstance();
                        }
                    }
              }
                 return s;
        }
}
public class Test7 {
        
        public static void main(String[] args) {
                
           single ss=single.getInstance();
        }
}
 
 |