一个简单的单例模式的类

  public class Singleton {
	private Singleton(){}
	private static Singleton instance;
	public static Singleton getInSingleton(){
		if(instance == null){
			synchronized (Singleton.class) {
				if(instance == null){
					instance = new Singleton();
				}
			}
		}
		return instance;
	}
  }

私有的构造方法不能别其他类实例化,只能在本类中使用new关键字实例化

  

原文地址:https://www.cnblogs.com/xlh91118/p/3838367.html