0PricingLogin
Dart Academy · Lesson

Initializer Lists and Redirecting

Set finals and reuse constructors.

Setting final Fields

A final field must be set before the constructor body runs. The initializer list is the perfect place to give it its one value.

class Circle {
  final double area;
  Circle(double r) : area = 3.14 * r * r;
}

The Initializer List Syntax

After the parameter list, add a colon and comma-separated assignments. This initializer list runs before the constructor body.

Point(int x, int y) : x = x, y = y;

All lessons in this course

  1. Default and Parameterized Constructors
  2. Named Constructors for Clear Intent
  3. Initializer Lists and Redirecting
  4. Factory and const Constructors
← Back to Dart Academy