java单利模式写法
public class Something { private Something() { } private static class LazyHolder { public static final Something INSTANCE = new Something(); } public static Something getInstance() { return LazyHolder.INSTANCE; } }
这样的懒汉单例模式的实现,唯一的缺点是当
Something方法构造失败后,instance返回的是一个null