简而言之,我试图构建一个抽象类的子类,所有这些都是单例。我想只把单身人士的“逻辑”放在超级班里。这在Java中可能吗?这里是代码:从抽象类构建单例
public abstract class Table {
//the static singleton instance. this will be inherited by subclasses of this class.
protected static Table m_Instance;
/**
* @param tableName the database table name.
*/
protected Table(String tableName, List<Column> columns) {
TABLE_NAME = tableName;
if(columns != null) {
if(!m_Columns.isEmpty())
m_Columns.clear();
m_Columns.addAll(columns);
} else {
throw new IllegalStateException("the columns list was null. this is a developer error. please report to support.");
}
}
protected static Table getInstance() {
if(m_Instance == null)
m_Instance = <? extends Table>;
}
}
这里仅仅是一个做广告的澄清执行:
public class CallTable extends Table {
//this class would inherit 'getInstance()' and the method would return a 'CallTable' object
}