Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Scala Pattern Matching
object patterns {
abstract class Foo
class Bar(val bar: Int) extends Foo
class Baz(val baz: String) extends Foo
def handle(f: Foo) =
f match {
case b: Bar => b.bar
case b: Baz => b.baz
}
handle(new Bar(42)) //> res0: Any = 42
handle(new Baz("Luhrmann")) //> res1: Any = Luhrmann
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment