Skip to content

Instantly share code, notes, and snippets.

@piperniehaus
Created May 8, 2018 16:20
Show Gist options
  • Save piperniehaus/94d288d8b8db2c17880b9785e6a4eb03 to your computer and use it in GitHub Desktop.
Save piperniehaus/94d288d8b8db2c17880b9785e6a4eb03 to your computer and use it in GitHub Desktop.
sealed class Pet
data class Dog(val name: String, val breed: String, val tricks: Array<String>) : Pet()
data class Cat(val name: String, val breed: String) : Pet()
data class Bird(val name: String, val breed: String, val words: Array<String>) : Pet()
fun playWithPet(pet: Pet):String{
when(pet){
is Dog -> println("You played with a DOG!")
is Cat -> println("You played with a CAT!")
}
return "I am happy because I am playing with pets"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment