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;
}
}
转载于:https://www.cnblogs.com/icenter/archive/2011/03/18/1988504.html