- public class Singleton{
- private static Singleton instance;
- //让构造函数为 private,这样该类就不会被实例化
- private Singleton(){}
- public static Singleton getInstance(){
- if(instance ==null) {
- instance =new Singleton();
- }
- return instance;
- }
- }
来源: http://www.bubuko.com/infodetail-1970211.html