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
- Why Generics Beat dynamic
- Generic Classes and Methods
- Bounded Type Parameters With extends
- Generic Collections in Practice