Search code examples
javaclassprocessingpriority-queue

Why can't I use "String" as a parameter for a priority queue?


I'm trying to implement the A* algorithm in Processing 3, and I decided to use a priority grid to store and prioritize explorable nodes. I had just decided to do a simple test to make sure I knew the syntax, but when I try to set the type of the queue to "String" or "Integer" I get the error The type filename.PriorityQueue is not generic; it cannot be parameterized with arguments <String> Any idea why this is happening?

import java.util.PriorityQueue;
import java.util.Comparator;

public class Test {
    public void main(String[] args) {
      PriorityQueue<String> pq= new PriorityQueue<String>(5,(a,b) -> a.length() - b.length());
    }
}

Solution

  • It appears you have a file called filename.java that has a type called PriorityQueue that does not take generics. You should most likely delete that file and then import the PriorityQueue you want:

    import java.util.PriorityQueue;