Skip to content

Instantly share code, notes, and snippets.

@cbeyls
Created April 28, 2019 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbeyls/2ce264ffe1e254243ea801267be7ff79 to your computer and use it in GitHub Desktop.
Save cbeyls/2ce264ffe1e254243ea801267be7ff79 to your computer and use it in GitHub Desktop.
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