简单的单例模式

package com.demo.sw.test;

public class HungerySingleton {
	
	private HungerySingleton(){
		
	}
	
	private static HungerySingleton s = new HungerySingleton();
	
	public static HungerySingleton getInstance(){
		return s;
	}

}


package com.demo.sw.test;

public class LazySingleton {
	private LazySingleton(){
		
	}
	private static LazySingleton ls = null;
	
	public static LazySingleton getInstance(){
		if(null == ls){
			ls = new LazySingleton();
		}
		return ls;
	}
	

}
posted @ 2011-03-18 23:23  标准小兵  阅读(177)  评论(0编辑  收藏  举报