Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
trait SentientBeing
trait Animal extends SentientBeing
case class Dog(name: String) extends Animal
case class Person(name: String, age: Int) extends SentientBeing
case class Lion(name: String) extends Animal
def printInfo(x: SentientBeing) = x match {
case Person(name, age) => name + " is " + age + " years old."
case Dog(name) => "the name is " + name
case _ => "I am not sure"
}
println(printInfo(new Person("She", 15)))
println(printInfo(new Dog("Tama")))
println(printInfo(new Lion("Lion")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.