我在这里发现了与我非常相似的问题,但我无法用其他帖子解决我的问题。抱歉,可能会重复发布...
我试图在我的终端中运行我的代码,但我收到了一个 javac 错误,即使我的代码在 Eclipse 中似乎很好。
public class MinHeap<E extends Comparable<E>> {
List<E> h = new ArrayList<E>();
ArrayList<E> arrayPostingsList = new ArrayList<E>();
//some more code
public double remove() {
E removedNode = h.get(0);
E lastNode = h.remove(h.size() - 1);
percolateDown(0, lastNode);
//this seems to be the problem
return (Double) removedNode;
}
这是我得到的错误
MinHeap.java:40: inconvertible types
found : E
required: java.lang.Double
Double B = (Double) removedNode;
^
1 error
有小费吗?
根据您的所有输入,我已经更改了返回类型并且它工作正常。
public E remove() {
E removedNode = h.get(0);
E lastNode = h.remove(h.size() - 1);
percolateDown(0, lastNode);
return removedNode;
}
谢谢!