public class GenericLinkedList<T extends Comparable<T>> implements Cloneable {
GenericListNode<T> head;
/**
* inserts a new node containing the data toAdd at the given index.
* @param index
* @param toAdd
*/
public <T> void add (int index, T toAdd) {
GenericListNode<T> node = new GenericListNode<T>((T) toAdd);
if (isEmpty()) {
head = node;
} else {
}
}
這是我的代碼,並由於某種原因,它與我做奇怪的錯誤,試圖在java中創建一個通用的鏈表類
head = node;
它說一個問題:
Type mismatch: cannot convert from GenericListNode<T> to GenericListNode <T extends Comparable<T>>
它建議鑄造節點是
head = (GenericListNode<T>) node;
乙它仍然給我的錯誤。
你覺得什麼'T'在'公共無效add'呢? –
你的類GenericListNode看起來如何 –