0Pricing
Kotlin Academy · Lesson

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

  1. sealed class vs sealed interface: When to Use Each
  2. Exhaustive when with Sealed Hierarchies
  3. Modeling UI State with Sealed Classes
  4. Nesting and Combining Sealed Hierarchies
← Back to Kotlin Academy