正如标题所说,为什么静态嵌套类单例线程安全?
public class Singleton {
private static class SingletonHolder {
public static Singleton instance;
public static Singleton getInstance() {
if (null == instance) {
instance = new Singleton();
}
}
}
public static Singleton getInstance() {
return SingletonHolder.getInstance();
}
}