我有以下 DataSource 类:
public class MyDataSource extends DataSource {
private static MyDataSource instance;
private static final String COLUMN_ONE = "One";
private static final String COLUMN_TWO = "Two";
public static MyDataSource getInstance() {
if (instance == null) {
instance = new MyDataSource("ID");
}
return instance;
}
private MyDataSource(String id) {
setDataProtocol(DSProtocol.CLIENTCUSTOM);
setDataFormat(DSDataFormat.CUSTOM);
setClientOnly(false);
constructDataSource(id);
}
private void constructDataSource(String id) {
setID(id);
DataSourceTextField one = new DataSourceTextField(COLUMN_ONE);
DataSourceTextField two= new DataSourceTextField(COLUMN_TWO);
setFields(one, two);
}
// and the rest of the class
}
我通过一些操作从另一个类创建这个类的一个实例MyDataSource ds = MyDataSource.getInstance();
,我需要销毁并重新创建它。我这样做ds.destroy(); ds = MyDataSource.getInstance();
了,但我注意到instance
销毁后它不为空,所以基本上第二次调用MyDataSource.getInstance();
是将旧对象返回给我。我怎样才能销毁这个实例?