私はAdjacency Listを使用してグラフを実装する際にチュートリアルタスクを実行していますが、コンストラクタに問題があります。私が持っている与えられたGraphTester.java
でJavaの一般化 - 指定された型にコンストラクタを適用することはできません
:
//Constructor cannot be applied to given types
FriendShipGraph<String> graph = new AdjList<String>();
その後FriendShipGraph.java
がインタフェースを提供します。
public interface FriendshipGraph<T extends Object> {
public static final int disconnectedDist = -1;
public abstract void addVertex(T vertLabel);
public abstract void addVertex(T srcLabel, T tarLabel);
//Other abstract methods
}
だから私はLinkedList
を実装するクラスを記述する必要があります。
public class SinglyLinkedList implements LinkedListInterface {
private Node head;
private int length;
public int getLength() {
return length;
}
public SinglyLinkedList() {
head = null;
length = 0;
}
//Other methods to manage the linked list
public class Node
{
private String value;
private Node nextNode;
public Node(String value) {
this.value = value;
nextNode = null;
}
//Other methods to manage node
}
}
そして私はの配列を使用しなければなりません私は私自身のテストファイルを書くとき
public class AdjList <T extends Object> implements FriendshipGraph<T> {
SinglyLinkedList[] AdjList = null;
//This is the constructor containing the error
public AdjList(T vertices) {
int qty = Integer.parseInt((String) vertices);
AdjList = new SinglyLinkedList[qty];
for (int i = 0; i < AdjList.length; i++)
AdjList[i] = new SinglyLinkedList();
}
}
は、しかし、私はエラーなしでこのようなAdjListオブジェクトを作成しますが、これはクラスが必要とするものではありません:
AdjList<String> aList = new AdjList<String>("9");
だから、誰も私を提案してくださいGraph
を実装するためにコンストラクタの修正方法どうもありがとうございます!
ヒント:javaコーディングガイドラインについて読む。フィールド名はlowerCaseから始まります。 – GhostCat
* FYI:* ''は ''と言っても非常に長いです –
Andreas