How do I add generic items to a generic ArrayList?

Viewed 1076

I have an assignment which requires me to implement a generic priority queue from scratch, however I'm getting an error that I don't think makes any sense.

public class PriorityQueue<E> {
     private ArrayList<E> items = new ArrayList<E>(0);
     ...
     public <E extends Comparable<E>> void insert(E newItem){

       if(numOfItems == 0){
          items.add(newItem); //ERROR: The method add(E) in the type ArrayList<E> 
                                       is not applicable for the arguments (E)
          rear++;
          numOfItems++;
       }else{
            //INCOMPLETE
       }
    }
}
3 Answers
Related