Below is the parent class DblyLinkList
package JavaCollections.list;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class DblyLinkList implements Iterable{
class DListNode {
private T item;
private DListNode prev;
private DListNode next;
DListNode(T item, DListNode p, DListNode n) {
this.item = item;
this.prev = p;
this.next = n;
}
}
.....
}
Below is the derived class LockableList,
package JavaCollections.list;
import JavaCollections.list.DblyLinkList.DListNode;
public class LockableList extends DblyLinkList {
class LockableNode extends DblyLinkList.DListNode {
/**
* lock the node during creation of a node.
*/
private boolean lock;
LockableNode(T item, DblyLinkList.DListNode p,
DblyLinkList.DListNode n) {
super(item, p, n); // this does not work
this.lock = false;
}
}
LockableNode newNode(T item, DListNode prev, DListNode next) {
return new LockableNode(item, prev, next);
}
public LockableList() {
this.sentinel = this.newNode(null, this.sentinel, this.sentinel);
}
.....
}
If class LockableNode extends DListNode in the above code, error:The constructor DblyLinkList.DListNode(T, DblyLinkList.DListNode, DblyLinkList.DListNode) is undefined occurs at line super(item, p, n)
This error is resolved by saying: class LockableNode extends DblyLinkList.DListNode
How do I understand this error? Why it got resolved?
解决方案
You are redeclaring the type variable T in the inner class. That means that within the inner class, the T of the outer class is hidden and cannot be referred to anymore.
Since you have a non-static inner class, you can just remove the type variable T there:
class DListNode { ... }
because it inherits it from the containing class (and probably you mean that the variables are the same, anyway).