Overview - Sealed classes with when exhaustive check
What is it?
Sealed classes in Kotlin are special classes that restrict which other classes can inherit from them. They let you define a fixed set of subclasses in one place. When you use a sealed class with a when expression, Kotlin can check if you have handled all possible cases, making your code safer and clearer.
Why it matters
Without sealed classes, you might miss handling some cases in your code, leading to bugs or crashes. Sealed classes with exhaustive when checks help catch these mistakes early, making programs more reliable. This is especially useful when dealing with different states or types that must be handled distinctly.
Where it fits
Before learning sealed classes, you should understand basic classes, inheritance, and when expressions in Kotlin. After this, you can explore advanced pattern matching, data classes, and Kotlin's type system features like inline classes or enums.