Java抽象クラスとジェネリック関数に問題があります。実装はDijkstraのアルゴリズムのグラフのノードクラスです。Java抽象クラスジェネリックメソッドパラメータ
public abstract class Node {
float distance;
Node parent;
public void relax(Node parent, Edge edge, PriorityQueue<? extends Node> priorityQueue) {
if (this.distance > parent.distance + edge.weight){
this.distance = parent.distance + edge.weight;
this.parent = parent;
priorityQueue.remove(this);
priorityQueue.add(this);
}
}
}
問題が線である:
priorityQueue.add(本) (抽象)
この参照ためNodeクラスには、プライオリティキューに追加することはできませんし、実際にタイプをすべきですか?ノードのサブクラスであるはに表示されますか?ノードを拡張します。どのようにこのサブクラスの型を参照するのですか?
ありがとうございます。
関連:http://stackoverflow.com/questions/34513926/is-extends-exclusivity-of-method-parameters – VGR