单例-java-代码
public class Singleton { private static Singleton instance;
private Singleton() {
// private constructor
}
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
//使用方法 Singleton singleton = Singleton.getInstance();
原文地址: http://www.cveoy.top/t/topic/qVu 著作权归作者所有。请勿转载和采集!