I found very similar questions to mine here, but I cannot work my problem out with the other posts. Sorry for the double posting maybe...
I am trying to run my code in my terminal but I am getting a javac error, even though my code seems to be fine in 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;
}
This is the error I get
MinHeap.java:40: inconvertible types
found : E
required: java.lang.Double
Double B = (Double) removedNode;
^
1 error
Any tips?
With all your input I have changed the return type and it is working fine.
public E remove() {
E removedNode = h.get(0);
E lastNode = h.remove(h.size() - 1);
percolateDown(0, lastNode);
return removedNode;
}
Thanks!