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