KtKotlin · Lesson 4 of 8
Classes & Data Classes
A Java class with getters, setters, equals, hashCode, and toString is ~50 lines. The Kotlin data class equivalent is one. This lesson is why people switch.
◆ Note
Sealed classes + when is Kotlin's answer to Rust enums / TypeScript discriminated unions: model 'a value that is one of N shapes' and the compiler guarantees every shape is handled. Android code uses this pattern for UI state constantly.
Sealed classes + when is Kotlin's answer to Rust enums / TypeScript discriminated unions: model 'a value that is one of N shapes' and the compiler guarantees every shape is handled. Android code uses this pattern for UI state constantly.