【发布时间】:2011-11-29 09:47:53
【问题描述】:
我有如下界面:
interface IBasicListNode<T> {
/**
* Returns the current element
*/
public T getElement();
/**
* Gets the next ListNode. Returns null if theres no next element
*/
public IBasicListNode<T> getNext();
/**
* Sets the next ListNode
*/
public void setNext(IBasicListNode<T> node);
}
还有一个班级:
class BasicListNode<T> implements IBasicListNode<T> {
protected T _elem;
protected BasicListNode<T> _next;
public T getElement() {
return this._elem;
}
public BasicListNode<T> getNext() {
return this._next;
}
public void setNext(BasicListNode<T> node) {
this._next = node;
}
/**
* Transverse through ListNodes until getNext() returns null
*/
public BasicListNode<T> getLast() {
BasicListNode<T> tmp = this;
while (tmp != null) {
tmp = tmp.getNext();
}
return tmp;
}
}
我得到了以下错误:
jiewmeng@JM-PC:/labs/Uni/CS1020/Lab/03/prob 2/LinkedList$ javac BasicListNode.java
BasicListNode.java:1: BasicListNode is not abstract and does not override
abstract method setNext(IBasicListNode<T>) in IBasicListNode
class BasicListNode<T> implements IBasicListNode<T> {
^
为什么 java 没有检测到 BasicListNode<T> implements IBasicListNode<T>?
【问题讨论】:
-
请注意,您的 setNext 方法的签名在超类和具体类中是不同的,因此您没有覆盖它。
-
@Yar,我更新了 Interface & Error ,还是不行
标签: java