[英]Java generic type of a generic type
How do I something like this in Java 我如何在Java中这样的事情
class TreeNode<Item<K,V>> {
}
The code above does not compile. 上面的代码无法编译。
You have to declare K
and V
to be generic parameters and you have to declare the name of the type parameter you want bound to Item<K, V>
. 您必须声明
K
和V
为通用参数,并且必须声明要绑定到Item<K, V>
的类型参数的名称。 Assuming that Item
is a predefined generic type, you can do something like this, for instance: 假设
Item
是预定义的泛型类型,则可以执行以下操作,例如:
class TreeNode<K, V, X extends Item<K, V>> {
...
}
Or perhaps (and more likely) you don't need a separate type parameter X
and just need to declare K
and V
as type parameters: 或者,也许(而且更有可能)您不需要单独的类型参数
X
而只需声明K
和V
作为类型参数:
class TreeNode<K, V> {
private Item<K, V> mItem;
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.