ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Follow publication

Member-only story

Learning by Example

Kotlin: Sealed Classes

A concrete example of when you might use sealed classes in Android

3 min readJul 29, 2019

--

Sealed Classes, not Seal Classes!

There have already been quite a few articles written on the topic of Kotlin sealed classes and so I am not going to rehash here what I believe others to have already adequately covered. Instead this article will demonstrate a practical example of utilizing sealed classes in Android code so that you can get a better idea of how and when you might leverage them.

In our example we will build off of the Creating an Android App Launcher article that I wrote last month. In that article I showed how one might go about creating a feature within their app for launching other, third-party apps. If you haven’t already checked that article out then you may want to jump over and give it a quick read. If you did already read the article and also checked out the accompanying GitHub sample project then you may have noticed that inside of the AppLauncherViewModel class there was an inner, sealed class named App and one concrete subclass of App named AppInfo. Here they are again for the sake of convenience:

--

--

ITNEXT
ITNEXT

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Responses (1)

Write a response