我創建了一個名爲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