Bounded Type Parameters With extends
Constrain what a generic can accept.
When Any Type Is Too Much
A plain type parameter accepts every type, but sometimes you need more. You may want to call a method that only certain types provide. 🔒
The Bound With extends
You can add a bound using extends. It says the type parameter must be a given type or a subtype of it.
class Cage<T extends Animal> {}All lessons in this course
- Why Generics Beat dynamic
- Generic Classes and Methods
- Bounded Type Parameters With extends
- Generic Collections in Practice