我想知道这个scala符号是什么: _@
。
(搜索引擎与怪异的字符有麻烦,因此很难在Google上找到任何东西...)
这是上下文:
def doNodeParse(json: JValue): TreeNode = {
json match {
case JObject(List(JField("Condition", JObject(List(JField("var", JString(variableName)), JField("Operation", JString("LT")), JField("Value", JDouble(threshold))))),
JField("onTrue", _@ onTrue),
JField("onFalse", _@ onFalse),
JField("onMissing", _@ onMissing)
)) =>
LessThanNode(variableName, threshold, doNodeParse(onTrue), doNodeParse(onFalse), doNodeParse(onMissing))
case _ => {
throw new Error("failed parsing json!")
}
}
}
(onTrue
,onFalse
,onMissing
的类型是JsonAST.JValue
)
在模式匹配中省略_
和@
之间的空间是合法的,因此在这种情况下,它与
case JObject(List(JField("Condition", JObject(List(JField("var", JString(variableName)), JField("Operation", JString("LT")), JField("Value", JDouble(threshold))))),
JField("onTrue", _ @ onTrue),
JField("onFalse", _ @ onFalse),
JField("onMissing", _ @ onMissing)
)) =>
LessThanNode(variableName, threshold, doNodeParse(onTrue), doNodeParse(onFalse), doNodeParse(onMissing))
@运算符的效果是使左侧匹配的值与比赛右侧的名称相匹配。