可能重复:
Why does pattern matching in Scala not work with variables?
Pattern match for variable in scope (Scala)
例如我有代码
def equals(value1:String, value2:String) = value1 match {
case value2 => true
case _ => false
}
我找到了解决方法,但我不太喜欢语法
def equals(value1:String, value2:String) = value1 match { case v if v == value2 => true case _ => false }
答案 0 :(得分:7)
使用反引号括号值2:
case `value2` => true