我有一个方法将一个char [] []作为参数(基本上是一个NxN字符网格),并且正在利用ArrayDeque来查看整个二维数组。我想从ArrayDeque取出一个char [] []对象的行和列,目前使用:来自ArrayDeque对象的2d char数组的尺寸
ArrayDeque stack=new ArrayDeque();
stack.push(grid[0][0]); //grid being the 2d array passed to the method
char[][] temp=(char[][]) stack.pop();
int row=temp.length-1;
int column=temp[0].length-1;
此编译在Eclipse中,但在运行时会抛出一个ClassCastException。有没有办法在上面第二行没有char [] []大小写的情况下获取行和列?
某些ClassCastException仅在运行时抛出,因此这是正常行为。 –