Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created December 31, 2015 06:49
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 Shinpeim/045e28abedf906c320c7 to your computer and use it in GitHub Desktop.
Save Shinpeim/045e28abedf906c320c7 to your computer and use it in GitHub Desktop.
sealed trait T
class A extends T {
def f:String = "A"
}
class B extends T {
def g:String = "B"
}
val a = new A
val b = new B
def f(x: T): String = x match {
case a: A => a.f
case b: B => b.g
}
println(f(a)) // => A
println(f(b)) // => B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment