Below is the parent class of DblyLinkList
package JavaCollections.list; import java.util.Iterator; import java.util.NoSuchElementException; public class DblyLinkList<T> implements Iterable<T>{ class DListNode<T> { private T item; private DListNode<T> prev; private DListNode<T> next; DListNode(T item, DListNode<T> p, DListNode<T> n) { this.item = item; this.prev = p; this.next = n; } } ..... }
The following is a derived class of LockableList ,
package JavaCollections.list; import JavaCollections.list.DblyLinkList.DListNode; public class LockableList<T> extends DblyLinkList<T> { class LockableNode<T> extends DblyLinkList<T>.DListNode<T> { /** * lock the node during creation of a node. */ private boolean lock; LockableNode(T item, DblyLinkList<T>.DListNode<T> p, DblyLinkList<T>.DListNode<T> n) { super(item, p, n); // this does not work this.lock = false; } } LockableNode<T> newNode(T item, DListNode<T> prev, DListNode<T> next) { return new LockableNode(item, prev, next); } public LockableList() { this.sentinel = this.newNode(null, this.sentinel, this.sentinel); } ..... }
If the class LockableNode<T> extends DListNode<T> in the above code, the error : The constructor DblyLinkList<T>.DListNode<T>(T, DblyLinkList<T>.DListNode<T>, DblyLinkList<T>.DListNode<T>) is undefined occurs on the line super(item, p, n)
This error is resolved by saying: class LockableNode<T> extends DblyLinkList<T>.DListNode<T>
How can I understand this error? Why is this allowed?
source share