Generic Classes

In this lesson, you will learn to use generic classes.

Generic Classes

Generic classes help restrict the type of values accepted by the class. These supplied values are known as the generic parameter(s).

In the following example, the class FreshProduce is restricted to accept only the Product data type. It is acceptable to use FreshProduce without the <Product> parameter as Dart will assume it to be of the type Product. However, if any other data type other than the allowed type is passed, you’ll see a compile-time error.

The FreshProduce Class

The FreshProduce class is ...