Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 12, 2015 14:26
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 shigemk2/a595b00ff826422e9c4b to your computer and use it in GitHub Desktop.
Save shigemk2/a595b00ff826422e9c4b to your computer and use it in GitHub Desktop.
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