Addem
Addem

Reputation: 3919

Make a 2D array of Objects in Java

I’ve written the code

Object[][] cells = new Object[10][10];

which I am hoping to later cast to

cells = (Cell[][]) cells;

but when I do I get a syntax error saying that it did not expect a semicolon where I have placed it, but instead expected what looks like white space. If this is not the correct way to construct a 2D Object array then what is?

Upvotes: 0

Views: 117

Answers (1)

Mureinik
Mureinik

Reputation: 310993

If you want a 2D array of Cells, you should create a 2D array of Cells, not of Objects:

Cell[][] cells = new Cell[10][10];

Upvotes: 1

Related Questions