设计模式--创建者--单例
单例模式的时机是当实例存在多个会引起程序逻辑错误的时候。比如类似有序的号码生成器这样的东西,电话号码集
public class Singleton {private static Singleton instance = null;private Singleton() {}public static Singleton getInstance() {if (instance == null) {instance = new Singleton();}return instance;}public static void main(String[] args) {System.out.println(Singleton.getInstance());System.out.println(Singleton.getInstance());}}