0PricingLogin
Dart Academy · Lesson

Generic Classes and Methods

Parameterize your own types.

Your Own Generics

Built-in types like List are generic, and you can write your own too. A type parameter lets your class adapt to whatever type the caller picks. 🧩

Naming the Type Parameter

You add a type parameter in angle brackets after the class name. The letter T is a common placeholder that stands in for a real type.

class Box<T> {
  T value;
  Box(this.value);
}

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