1

在处理这个铸造对象和诸如此类的概念时,我现在非常困惑,但我相信我已经非常接近完成了。如果您可以查看我的代码并提示我可以做些什么来停止收到此错误,那就太好了。

public E remove(int position){
    position -= 1;
    if(outOfBounds(position))
        throw new RuntimeException("Invalid position.");
    E[] temp;
    temp = (E[])storage[position];// around here is where I receive the error
    currentSize--;
    shiftLeft(position);
    return temp[position];
}// DONE

这是我在第一次回复的建议之后的第二次尝试(但是,仍然收到未经检查的强制转换错误):

public E remove(int position){
    position -= 1;
    if(outOfBounds(position))
        throw new RuntimeException("Invalid position.");
    E[]temp = (E[])new Object[maxSize];
    temp = (E[])storage[position];
    currentSize--;
    shiftLeft(position);
    return temp[position];}// DONE
4

1 回答 1

0

我没有看到“存储”的定义,但我认为它是一个数组。您不能将一种类型的数组转换为另一种类型的数组。您只能将 Array 强制转换为超类,例如 Object。

于 2017-07-17T16:30:03.173 回答