I have an outer class (LinkedStack
) that has an inner node class. Is it necessary to declare the inner Node class with the same generic like
If the inner class is a static class then yes, otherwise no.
I.e.:
class LinkedStack<T> {
// references to T refer to LinkedStack's T.
static class Node<T> {
// references to T refer to Node's T.
T data;
}
// ...
Node<T> node;
}
or:
class LinkedStack<T> {
// references to T refer to LinkedStack's T.
class Node {
// references to T refer to LinkedStack's T.
T data;
}
// ...
Node node;
}