如果单例实现如下,
class Singleton {
private static Singleton instance = new Singleton();
public static Singleton getInstance() {
return instance;
}
}
这个实现与惰性初始化方法有什么不同?在这种情况下,将在加载类时创建实例,并且仅在第一次活动使用时才加载类本身(例如,Singleton.getInstance() 而不是在您声明例如 Singleton singleton = null; 时)
即使使用惰性初始化方法,实例也是在调用 getInstance() 时创建的
我在这里错过了什么吗?