package com.Isay.learn;
/**
* @author isay_me
* @date 2019/10/22
* @time 11:32
* @target:
*/
public class Singleton {
private static Singleton instance;
private Singleton(){}
public static Singleton getInstance(){
if (instance == null){
synchronized (Singleton.class){
if (instance == null){
instance = new Singleton();
}
}
}
return instance;
}
}
本文详细介绍了Java中单例模式的实现方式,通过一个具体的Singleton类的代码示例,展示了如何确保类只有一个实例,并提供一个全局访问点。
1713

被折叠的 条评论
为什么被折叠?



