What mean this expression in Generic

78 Views Asked by At

Can someone please explain to me what this expression in java means:

class BinaryNode<AnyType extends Comparable<? super AnyType>>

What does "AnyType extends Comparable" mean?

1

There are 1 best solutions below

0
On BEST ANSWER

This declares a generic type parameter called AnyType. The rest of the declaration, extends Comparable<? super AnyType>, places an upper bound on what AnyType can be. Specifically, whatever AnyType is must be Comparable, and Comparable's type argument can be what AnyType is, or anything that is a superclass of that type. E.g. it could be Integer, because Integer is Comparable<Integer>. However, it could be some class that is Comparable<Object>, because Object is the superclass to all object types.