Q:

Inner Class with parameter of Outer Class Type

I would like to create an inner class parametrized on the type of the outer class.
I should say first that I realize there may be a better way to achieve something like my desired result, and I am open to suggestions there, but I'll describe the situation as it stands:
I have a class Node<T> and an attempt at an inner class declaration as below:
public class Node<T> {
    ...

    class NodeIterator<Node<T>> implements Iterator {
        ...
    }
}

This causes a syntax error during compilation, and I infer that this is due to the my use of the outer class, although I do not know this for sure.
Thanks!

A:

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.

