java - How to inherit parent's inner class in this code? -
below parent class 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; } } ..... }
below derived class 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 node during creation of node. */ private boolean lock; lockablenode(t item, dblylinklist<t>.dlistnode<t> p, dblylinklist<t>.dlistnode<t> n) { super(item, p, n); // 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 class lockablenode<t> extends dlistnode<t>
in above code, error:the constructor dblylinklist<t>.dlistnode<t>(t, dblylinklist<t>.dlistnode<t>, dblylinklist<t>.dlistnode<t>) undefined
occurs @ line super(item, p, n)
this error resolved saying: class lockablenode<t> extends dblylinklist<t>.dlistnode<t>
how understand error? why got resolved?
you redeclaring type variable t
in inner class. means within inner class, t
of outer class hidden , cannot referred anymore.
since have non-static inner class, can remove type variable t
there:
class dlistnode { ... }
because inherits containing class (and mean variables same, anyway).
Comments
Post a Comment