sealed class vs sealed interface: When to Use Each
Understand the difference between sealed classes and interfaces in Kotlin.
Sealed Types in Kotlin
Sealed classes and interfaces restrict the class hierarchy to a known set of subtypes, enabling exhaustive when expressions.
sealed class Basics
A sealed class restricts subclassing to the same package (Kotlin 1.5+) or same file.
sealed class Shape
class Circle(val radius: Double) : Shape()
class Rectangle(val w: Double, val h: Double) : Shape()
object Unknown : Shape()All lessons in this course
- sealed class vs sealed interface: When to Use Each
- Exhaustive when with Sealed Hierarchies
- Modeling UI State with Sealed Classes
- Nesting and Combining Sealed Hierarchies