饿汉式单例模式
2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
餓漢式單例是指在類被加載的時候,唯一實例已經(jīng)被創(chuàng)建 懶漢式單例是指在類加載的時候不創(chuàng)建單例,只有在請求getInstance() 方法時創(chuàng)建實例
public class Singleton {private static Singleton singleton=new Singleton();//防止該類在外部實例化private Singleton(){}public static synchronized Singleton getInstance(){return singleton;}}轉(zhuǎn)載于:https://my.oschina.net/u/3218528/blog/845037
總結(jié)
- 上一篇: css 背景和渐变
- 下一篇: HTML5 本地文件操作之FileSys