14. PATTERN MATCH
使ったもの
• 柔軟なswitch文
instanceList foreach {
_ match {
case ClassA => println(“This is ClassA”)
case ClassB if _.hasChild()
=> println(“This is ClassB having ching”)
case _ => println(“other class”)
}
}
(foreach要素を受ける)
(クラスでマッチング)
(さらに if で条件付き)
(デフォルト)
16. SYNTAX SUGAR
使ったもの
• 文字列 -> XML
val nodes:NodeSeq = XML loadString str
• XMLタグ取得
xml “tagName”
• XML要素取得
xml “@attrName”
nodes foreach { _ match { case ~ } }