Module 06 of 12

Data & Sealed Classes

Lessons

About This Module

Many classes exist only to hold data, and Kotlin makes them almost free to write. A data class automatically generates toString, equals, hashCode, copy, and component functions for destructuring, so you can model your data in a single line instead of pages of boilerplate.

You'll then meet sealed classes and interfaces, which restrict a class hierarchy to a known set of subtypes. Combined with when, they let the compiler check that every case is handled, which makes them ideal for modelling states and results. You'll also see how they compare to enum classes and when to choose each.

Watch the lessons in order, then continue on to Collections & Sequences.

Lessons

4 videos
01

Kotlin Data Class Tutorial - toString, equals, copy, componentN functions

Introduces data classes in Kotlin and the benefits you get from the functions they generate automatically.

02

Kotlin Data classes with examples

Shows how to implement data classes, why we use them, and how the equals and hashCode functions work.

03

Kotlin For Beginners (Classes, Sealed Classes, Sealed Interfaces)

Introduces sealed classes and sealed interfaces in Kotlin and the differences between them and enum classes.

04

Sealed Classes/Interfaces VS Enum Classes in Kotlin

Compares sealed classes, sealed interfaces, and enum classes in Kotlin.