Scala: Can you use “foo match { bar }” in an expression without parentheses?
问题 Why are the parentheses needed here? Are there some precedence rules I should know? scala> 'x' match { case _ => 1 } + 1 <console>:1: error: ';' expected but identifier found. 'x' match { case _ => 1 } + 1 ^ scala> ('x' match { case _ => 1 }) + 1 res2: Int = 2 Thanks! 回答1: As Agilesteel says, a match is not considered as a simple expression, nor is an if statement, so you need to surround the expression with parentheses. From The Scala Language Specification, 6 Expressions, p73, the match is