您的位置:首页 > 编程语言 > Java开发

Java 经典单例模式代码

2014-10-29 21:14 274 查看
public class Singleton {
private static Singleton uniqueInstance = null;

private Singleton() {
// Exists only to defeat instantiation.
}

public static Singleton getInstance() {
if (uniqueInstance == null) {
uniqueInstance = new Singleton();
}
return uniqueInstance;
}
// Other methods...
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: