У меня есть универсальный класс ShortestPathVertex
, который реализует Comparable
:
public class ShortestPathVertex<E extends Number> implements VertexInterface, Comparable<ShortestPathVertex<E>>
И еще один универсальный класс MinPriorityQueue
, для которого требуется параметр типа Comparable
:
public class MinPriorityQueue<T extends Comparable<T>>
И мне нужно создать экземпляр MinPriorityQueue
с ShortestPathVertex
в качестве параметра типа:
public static <E extends Number, T extends ShortestPathVertex<E>> void Dijkstra(WeightedDirectedGraph<T, E> G, int s) {
MinPriorityQueue<T> Q = new MinPriorityQueue<>(G.getVertices(), G.V()); // error
}
При компиляции выдается ошибка:
ShortestPath.java:60: error: type argument T#1 is not within bounds of type-variable T#2
MinPriorityQueue<T> Q = new MinPriorityQueue<>(G.getVertices(), G.V());
^
where T#1,E,T#2 are type-variables:
T#1 extends ShortestPathVertex<E> declared in method <E,T#1>Dijkstra(WeightedDirectedGraph<T#1,E>,int)
E extends Number declared in method <E,T#1>Dijkstra(WeightedDirectedGraph<T#1,E>,int)
T#2 extends Comparable<T#2> declared in class MinPriorityQueue
ShortestPath.java:60: error: cannot infer type arguments for MinPriorityQueue<>
MinPriorityQueue<T> Q = new MinPriorityQueue<>(G.getVertices(), G.V());
^
2 errors
Учитывая, что ShortestPathVertex
реализует Comparable
я не понимаю, на что это жалуется.Почему говорится, что ShortestPathVertex
не имеет границ Comparable
и как мне это исправить.Я использую Java 7.0.