0Pricing
Dart Academy · Lesson

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

  1. Why Generics Beat dynamic
  2. Generic Classes and Methods
  3. Bounded Type Parameters With extends
  4. Generic Collections in Practice
← Back to Dart Academy