Skip to content

Comment on Clean Coder: The Dark Path (2017)parent

Comments

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.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.