| 发表于:2007-07-14 14:40:141楼 得分:0 |
// 懒汉: public class singleton { private static singleton obj = null; private singleton() { // todo auto-generated constructor stub } public synchronized static singleton getinstance() { if (obj == null) obj = new singleton(); return obj; } } // 饿汉: public class singleton { private static singleton obj = new singleton(); /** * */ private singleton() { // todo auto-generated constructor stub } public static singleton getinstance() { return obj; } } | | |
|