单例设计模式

package com.wyc.cn;

/**
 * 单例设计模式
 * @author buyi
 * @date 2015-09-03
 * **/
class SingLeton {
    private static SingLeton singLeton ;
    private SingLeton() {
        
    }
    
    public static SingLeton getInstance() {
        if(null == singLeton) {
            singLeton = new SingLeton() ;
        }
        
        return singLeton ;
    }
}

public class SingLetonTest {
    public static void main(String[] args) {
        SingLeton singLeton = SingLeton.getInstance();
        SingLeton singLeton1 = SingLeton.getInstance();
        System.out.println(singLeton == singLeton1);
    }
}

posted on 2015-09-04 15:31  javawg  阅读(98)  评论(0)    收藏  举报

导航