Skip to content

Instantly share code, notes, and snippets.

@cbeyls
Created Apr 28, 2019
Embed
What would you like to do?
sealed class Animal {
// Cats are simple. A cat is a cat.
object Cat : Animal()
sealed class Dog : Animal() {
abstract val breed: String?
class DogWithBreed(override val breed: String) : Dog()
companion object : Dog() {
override val breed: String?
get() = null
operator fun invoke(breed: String) = DogWithBreed(breed)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment