在我的子类中我有这样的:使用属性在超类
protected String[] columns = {"column1", "column2"};
虽然我的父类中我有一个会存储这些HashMap中的方法。
public HashMap<Integer, String> getColumns() {
HashMap<Integer, String> columnsMap = new HashMap<>();
for (int i = 0; i < this.columns.length; i++) {
columnsMap.put(i + 1, this.columns[i]);
}
return columnsMap;
}
但是,看起来,我不能简单地使用String[] columns
属性在我的子类。 我将如何做到这一点?
我相信你的选择是使用单例,或者多例,或使其成为抽象方法返回父对象中的String [],并返回子对象的String []。 – 2014-10-07 16:15:33
如果您将Super类作为Abstract,您将如何访问此结果(来自子类的值)。你如何调用getColumns()方法。只是想知道这可能有用的场景。 (假设你正在接受接受的答案) – Suvasis 2014-10-07 17:39:39