The power of sealed classes in Kotlin

A single type, many possibilities

Andrew Lord
ProAndroidDev
Published in
5 min readFeb 2, 2020

--

Wouldn’t it be great if you could represent a single type that can come in different forms, each able to be constant or carry their own data? If programming in Kotlin, we are in luck as that is exactly what a sealed class is perfect for!

Enums or enumerated types have existed in many different programming languages for years and allows us to represent a type whose value is taken from a limited set of values. Kotlin takes this concept and evolves into something much more powerful…

--

--

Mobile Lead @WorkiroApp . Android and iOS Engineer. Author @ http://lordcodes.com. Avid gamer and music fan.