Skip to content

Instantly share code, notes, and snippets.

@s1monw1
Created May 29, 2023 08:14
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 s1monw1/85be7753c4487b1524bcd007d7b10a03 to your computer and use it in GitHub Desktop.
Save s1monw1/85be7753c4487b1524bcd007d7b10a03 to your computer and use it in GitHub Desktop.
sealed class Mammal(val name: String)
class Cat(val catName: String) : Mammal(catName)
class Human(val humanName: String, val job: String) : Mammal(humanName)
fun greetMammal(mammal: Mammal): String {
return when (mammal) {
is Human -> "Hello ${mammal.name}; You're working as a ${mammal.job}"
is Cat -> "Hello ${mammal.name}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment