What's the sense of this class definition, what's kind of class is that?
class Node<K extends Comparable<? super K>,V>
This is a generic class definition. It translates to:
Comparable
Comparable
itself, in this case, takes some type as parameter, let's call it T.Edit: Ok, since an example was requested, a simple instantiation of this class could be:
Node<Integer, String> node = new Node<Integer, String>();
Since the Integer
class implements Comparable<Integer>
it fits the above description nicely (note that super
also allows type T to the the same type as K).
V has no constraints, so it can be any type.
It's a generic class of types K
and V
, where K
is a type that extends Comparable
of any class that is a superclass of K
.
Looks like it's from an implementation of a red-black tree designed for explanatory purposes:
Red-black tree implemented in Java
Beyond that, it's a class called Node
that takes parameters K and V, where K extends Comparable
, which takes a parameter that is itself a superclass of K.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With