我是java singleton的新手,我想创建我的类singleton
,所以我在我的代码中有一个它的实例。
我想成为单例的类是扩展另一个类,其构造函数有两个条目。
下面是代码,我做了什么!但这不正确! 我怎么能写我的单身人士
public class Singleton extends Parent{
private Ui ui;
private Store store;
private singleton(Ui ui, Store store) {
super(ui, store);
// TODO Auto-generated constructor stub
}
private static class singletonHolder() {
// My problem is here: how to set value for super class?!
public static final singleton INSTANCE = new singleton();
}
public static singleton getInstance() {
return singletonHolder.INSTANCE;
}
protected Object readResolve() {
return getInstance();
}
public void SetStore(Store dstore){
store = dstore;
}
public void SetUi(Ui uid){
ui = uid;
}
}