带列表的Java泛型
我想澄清一些事情。这是我的代码:带列表的Java泛型,java,list,generics,arraylist,Java,List,Generics,Arraylist,我想澄清一些事情。这是我的代码: List<GameObject>[] dynamicCells; //1 List<GameObject>[] staticCells; //2 dynamicCells = new List[numCells]; //3 staticCells = new List[numCells];
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
}
List[]dynamicCells//1.
列出所有单元格//2.
dynamicCells=新列表[numCells]//3.
staticCells=新列表[numCells]//4.
对于(int i=0;i
在第一步和第二步中,我创建了一个GameObject
列表引用的“空”数组。
在第三和第四步,我为一个列表数组分配内存,并返回其地址引用。在第5、6步中,我创建了一个新的ArrayList
引用,类型为GameObject
,我将其分配到我的列表中
最后,我得到了一个列表引用数组,每个引用都包含一个游戏对象的
ArrayList
。是这样吗?有没有更好的方法来解释这一点?1和2是变量声明,没有创建任何内容
3和4创建数组并将其分配给变量(在分配内存的过程中,但仅针对对象引用的数组)
5和6创建新的空通用ArrayList,分配给数组中的某个位置。没错。每个变量都是
列表
对象的数组。谢谢你的回答,正如我说的,我很困惑,但现在我确定:)