【发布时间】:2015-10-26 22:34:36
【问题描述】:
我有一个将 char[][] 作为参数的方法(基本上是一个 NxN 字符网格),并使用 ArrayDeque 来查看整个二维数组。我想从 ArrayDeque 中删除 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[][] 的情况下获取行和列?
【问题讨论】:
-
一些 ClassCastExceptions 仅在运行时抛出,因此这是正常行为。
标签: java casting arraydeque