package mode.single; public class Single { private static Single single; private Single() { } public static Single getInstance() { if (null == single) { System.out.println("第一次创建"); single = new Single(); } return single; } }
测试
package mode.single; public class Test { public static void main(String[] args) { Single s1 = Single.getInstance(); Single s2 = Single.getInstance(); Single s3 = Single.getInstance(); } }
原文地址:http://blog.csdn.net/u012613903/article/details/44036097