我正在为一些家庭作业进行链接列表分配,而我在使ListNode类工作时遇到了一些麻烦。每次编译我都会收到此错误。
C:\Users\Username\Dropbox\java\ListPkg\ListNode.java:32: error: cannot find symbol
node = next;
^
symbol: variable node
location: class ListNode<T>
where T is a type-variable:
T extends Comparable<T> declared in class ListNode
1 error
[Finished in 0.6s with exit code 1]
这是代码。我不知道我做错了什么,它可能是一个我很想念的简单修复。
package ListPkg;
public class ListNode<T extends Comparable <T>>
{
private T data;
private ListNode<T> nextNode;
public ListNode(T object)
{
setData(object);
setNext(null);
}
public ListNode(T object, ListNode<T> node)
{
setData(object);
setNext(node);
}
public void setData(T object)
{
data = object;
}
public T getData()
{
return data;
}
public void setNext(ListNode<T> next)
{
node = next;
}
public ListNode<T> getNext()
{
return nextNode;
}
}
答案 0 :(得分:2)
应该:
private ListNode<T> nextNode;
成为:
private ListNode<T> node;