public class Flight implements Comparable {
....
public int compareTo(Object obj){
Flight f = (Flight) obj;
Integer i1 = (Integer) f.priority;
Integer i2 = (Integer) priority;
if(f == null)
return 1;
else
return i2.compareTo(i1);
}
....
public class JavaPriorityFlightQueue {
public PriorityQueue flights;
....
public void joinQueue(Flight f){
flights.add(f);
Collections.sort(flights);
}
.....
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method sort(List) in the type Collections is not applicable for the arguments (PriorityQueue)
at section3.JavaPriorityFlightQueue.joinQueue(JavaPriorityFlightQueue.java:31)
at section3.FlightTest003.main(FlightTest003.java:19)
I used the exact same compareTo for a LinkedList and it works, and everything is the same I have not missed something out (I think). I do not understand how it works for LinkedList but not PriorityQueue.