[英]Generic type in inner class
I have an outer class ( LinkedStack<T>
) that has an inner node class. 我有一个具有内部节点类的外部类(
LinkedStack<T>
)。 Is it necessary to declare the inner Node class with the same generic like 是否有必要使用相同的泛型声明内部Node类?
private Node<T>
as opposed to 相对于
private Node
or does it not make any difference? 还是没有任何区别?
If the inner class is a static class then yes, otherwise no. 如果内部类是静态类,则为是,否则为否。
Ie: 即:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.