标签:style mamicode return code div nbsp turn class static
/** * 单例模式(懒汉) */ public class Single { private static Single single=null; private Single(){ } public static Single getInstance(){ if (single == null){ single=new Single(); } return single; }
测试是否为单例
public static void main(String[] args) { Single single1 = Single.getInstance(); Single single2 = Single.getInstance(); System.out.println(single1 == single2); }
标签:style mamicode return code div nbsp turn class static
原文地址:https://www.cnblogs.com/wanerhu/p/11060566.html