【发布时间】:2014-12-14 14:06:42
【问题描述】:
我想澄清一些事情。这是我的代码:
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 步中,我创建了一个 GameObject 类型的新 ArrayList 引用,我将其分配到我的列表中。
所以最后我得到了一个列表引用数组,每个引用都包含一个ArrayList 的游戏对象。这是正确的吗 ?有没有更好的方法来解释这一点?
【问题讨论】:
-
没错。每个变量都是
List对象的数组。
标签: java list generics arraylist