【设计模式之单例模式InJava】
生活随笔
收集整理的這篇文章主要介紹了
【设计模式之单例模式InJava】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 單例模式
1.1餓漢式(開發常用)
class SingleFirst {/*添加其他成員信息*/private static SingleFirst s1 = new SingleFirst();private SingleFirst(){}public static SingleFirst getInstance(){return s1;} }?
1.2 懶漢式
class SingleSecond {/*添加其他成員信息*/private static SingleSecond s2 = null;private SingleSecond(){}public static SingleSecond getInstance(){if(null==s2)s2 = new SingleSecond();return s2;} }
轉載于:https://www.cnblogs.com/huoshaofeng/p/5874658.html
總結
以上是生活随笔為你收集整理的【设计模式之单例模式InJava】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ListView position
- 下一篇: oracle+SQL优化实例