我创建了一个名为Grid
的类,我非常努力地定义嵌套的ArrayList
的容量。这是我目前有:定义多维数组列表的容量
public class Grid extends GameObject {
private int cols;
private int rows;
private int colWidth;
private int rowHeight;
private ArrayList<ArrayList<GameObject>> contents;
public Grid(int x, int y, int cols, int rows, int colWidth, int rowHeight, ID id) {
super();
this.x = x;
this.y = y;
this.cols = cols;
this.rows = rows;
this.colWidth = colWidth;
this.rowHeight = rowHeight;
//Here I want to define the contents
this.width = colWidth * cols;
this.height = rowHeight * rows;
this.id = id;
}
}
代码应该是这个样子:
this.contents = new ArrayList<ArrayList<GameObject>(cols)>(rows);
但是,这给出了一个错误。有谁知道如何解决这个问题,我真的很感激它!提前致谢!
我有点希望这是可能的,但这将不得不做。谢谢! – Trashtalk