JAVA 中类如何只实例化一次(单例模式)

以前只运用过单例模式,但是没有具体的了解过单例模式的含义,今天去面试让一下一个类只实例化一次,想了好久没想出来,回来查了资料才知道是单例模式,记录下来。

public class Singleton {
private static Singleton uniqueInstance = new Singleton();
private Singleton(){}
public static Singleton getInstance() {
return uniqueInstance;
}
}
posted @ 2017-07-03 12:51  silentax  阅读(1967)  评论(0)    收藏  举报