Simply do:
public class Node<T> {
...
class NodeIterator implements Iterator<Node<T>> {
...
}
}
As an inner class, an instance of NodeIterator
has an implicit reference to an outer Node
instance. For this reason, the type T
is still in scope within its body.
Note that an alternative would be to make NodeIterator
static
, losing the implicit outer reference:
static class NodeIterator<T> implements Iterator<Node<T>> {
...
}
Here, T
must be declared anew, and is different from the T
declared by the outer class.
See the Java Tutorials article on nested classes for more info.