2021
07-09
07-09
Android 单例模式的四种实现方式
目录一.饿汉式二.懒汉式三.双重检查加锁方式四.静态内部类方式总结一.饿汉式publicclassSingletionStarving{privatestaticfinalSingletionStarvingmInstance=newSingletionStarving();privateSingletionStarving(){}publicstaticSingletionStarvinggetInstance(){returnmInstance;}}构造函数用private修饰,外部无法访问声明静态对象时就初始化static关键字修饰,静态变...
继续阅读 >