0PricingLogin
Dart Academy · Lesson

sealed Classes and Exhaustive switch

Close a hierarchy the compiler can check.

A Closed Family

A sealed class defines a fixed set of subtypes. No code outside its file can add a new one, so the family is fully known.

sealed class Shape {}

Declaring Subtypes

Subclasses of a sealed type live in the same file. Together they form every possible variant the compiler must consider.

class Circle extends Shape {}
class Square extends Shape {}

All lessons in this course

  1. Final Fields and Deep Immutability
  2. sealed Classes and Exhaustive switch
  3. base, interface, and final Modifiers
  4. copyWith and Value Equality
← Back to Dart Academy