Last active
August 29, 2015 14:04
-
-
Save kevinpet/e2f34a67a7a82abaa2c8 to your computer and use it in GitHub Desktop.
Scala Pattern Matching
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
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