logoalt Hacker News

mh2266today at 2:35 PM0 repliesview on HN

sealed classes are just retrofitting sum types onto the JVM. If Kotlin could have used "enum" for it then they probably would have, like Swift and Rust did.

The main point of sealed classes is exhaustive `when` expressions:

    return when (val result = something()) {
      Result.Success -> // ...
      Result.Failure -> // ...
    }
If another subclass appeared at runtime, then the code would fall off the end of that when expression.