Skip to content

Instantly share code, notes, and snippets.

@avegancafe
Last active August 29, 2015 14:03
Show Gist options
  • Save avegancafe/ade70484ef5fd4f89061 to your computer and use it in GitHub Desktop.
Save avegancafe/ade70484ef5fd4f89061 to your computer and use it in GitHub Desktop.
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