恶汉
class God { private static God instance = new God(); private God() { } public static God GetInstance() { return instance; } }
懒汉
class God { private static God instance = null; private static object locker = new object(); private God() { } public static God GetInstance() { if (instance == null) { lock (locker) { if (instance == null) { instance = new God(); } } } return instance; } }