スーパークラス (GraphNode) とサブクラス (AStarNode) があります。どちらも別のクラスのメンバーになることができるため、それを使用するクラスをジェネリック クラス (GraphEdge) に変更しました。
このクラス内で、スーパークラスのいくつかのメンバー関数を呼び出したいのですが、コンパイラは次のように不平を言います:
The method addEdge(GraphEdge<T>) is undefined for the type T
どうすればこれを修正できますか、それとも私のアプローチは大丈夫ですか?
シナリオをより適切に説明するコードを次に示します。
public class GraphNode {
protected Graph graph;
public GraphEdge addEdge(){
//some code
}
}
public class AStarNode extends GraphNode {
protected GraphEdge predecessor;
}
//The from and to properties can be either AStarNode or GraphNode
public class GraphEdge<T> extends Entity {
protected T from;
protected T to;
public someMethod(){
from.addEdge(this);
}
}