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?
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?
Copyright © 2021 Jogjafile Inc.
This declares a generic type parameter called
AnyType
. The rest of the declaration,extends Comparable<? super AnyType>
, places an upper bound on whatAnyType
can be. Specifically, whateverAnyType
is must beComparable
, andComparable
's type argument can be whatAnyType
is, or anything that is a superclass of that type. E.g. it could beInteger
, becauseInteger
isComparable<Integer>
. However, it could be some class that isComparable<Object>
, becauseObject
is the superclass to all object types.