Created
February 12, 2015 14:26
-
-
Save shigemk2/a595b00ff826422e9c4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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