Search code examples
javapriority-queuejava-17

Type PriorityQueue is not generic in Java


When creating a PriorityQueue I get The type PriorityQueue is not generic; it cannot be parameterized with arguments <> .

import java.util.*;
public class PriorityQueue {
public static void main (String [] args) {

Queue<Double> queuePriority = new PriorityQueue<>();
        
        queue.offer(3.0);
        queue.offer(3.5);
        queue.offer(2.5);
        queue.offer(4.0);
        queue.offer(1.5);
        
        while (!queue.isEmpty()) {
            System.out.println(queue.poll());
        }
    }
}

If I click "Remove type arguments", I get Type mismatch: cannot convert from PriorityQueue to Queue<Double>.

Following recommended solutions in Eclipse lead to nowhere.


Solution

  • You have a naming conflict with Java's own PriorityQueue class and the compiler thinks you're instantiating your own class, not the built-in one. Just rename your class to something slightly different and it should be fine again.