在我的子類中我有這樣的:使用屬性在超類
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