我怎么用Java做这样的事?
class TreeNode<Item<K,V>> {
}上面的代码不编译。
发布于 2016-03-25 02:18:17
您必须声明K和V为泛型参数,并且必须声明要绑定到Item<K, V>的类型参数的名称。假设Item是预定义的泛型类型,您可以这样做,例如:
class TreeNode<K, V, X extends Item<K, V>> {
...
}或者(更有可能的)您不需要单独的类型参数X,只需要将K和V声明为类型参数:
class TreeNode<K, V> {
private Item<K, V> mItem;
...
}https://stackoverflow.com/questions/36213029
复制相似问题