Last active
September 15, 2015 18:37
-
-
Save isterin/5880053fbeaa9ae4cdbc 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
import java.util | |
import java.util.{Map => JMap, List => JList} | |
import scala.reflect.runtime.universe._ | |
object PatternMatching extends App { | |
val o: JMap[String, Any] = new util.HashMap[String, Any]() | |
val o2: JList[JMap[String, Any]] = new util.ArrayList[JMap[String, Any]]() | |
pmatch(o) | |
pmatch(o2) | |
def pmatch[T:TypeTag](o: T) = typeTag[T].tpe match { | |
case t if t =:= typeOf[JMap[String, Any]] => println(s"MAP: $t") | |
case t if t =:= typeOf[JList[JMap[String, Any]]] => println(s"LIST: $t") | |
case t => println(t) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment