我有一个通用类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。
慕的地10843
相关分类