Last active
August 29, 2015 14:03
-
-
Save avegancafe/ade70484ef5fd4f89061 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
abstract class A | |
case class A1(in: String) extends A | |
case class A2(num: Int) extends A | |
val test1: A = A1("Hello") | |
val test2: A = A2(1) | |
def receive (inObj: A) = { | |
/* | |
* option 1: | |
* Does not need "case" before "class" on lines 2 and 3 | |
*/ | |
inObj match { | |
case _: A1 => println("this") | |
case _: A2 => println("that") | |
} | |
/* | |
* option 2: | |
* More of a functional programming approach | |
*/ | |
inObj match { | |
case A1(string) => println(string) | |
case A2(number) => println(number) | |
} | |
} | |
receive(test2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment