我想澄清一些事情。這是我的代碼:Java泛型與列表
List<GameObject>[] dynamicCells; //1
List<GameObject>[] staticCells; //2
dynamicCells = new List[numCells]; //3
staticCells = new List[numCells]; //4
for (int i = 0; i < numCells; i++) {
dynamicCells[i] = new ArrayList<GameObject>(10); //5
staticCells[i] = new ArrayList<GameObject>(10); //6
}
在第一步和第二步,我創建的GameObject
列表引用一個「空」陣列。 在第三步和第四步中,我爲一個List數組分配內存,並返回其地址引用。在第5,6步中,我創建了一個新的ArrayList
參考,我在列表中分配了GameObject
。
因此,最後我剩下一個列表引用數組,每個列表引用都包含遊戲對象的ArrayList
。這是正確的嗎 ?有沒有更好的方法來解釋這一點?
這是正確的。每個變量都是一個List列表對象的數組。 – SamTebbs33 2014-10-19 14:09:23