简体   繁体   中英

Java generic type of a generic type

How do I something like this in 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> . Assuming that Item is a predefined generic type, you can do something like this, for instance:

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:

class TreeNode<K, V> {
    private Item<K, V> mItem;
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM