链接匹配表达式无法编译。
val x = Array("abc", "pqr")
x match {
case Array("abc", _*) => Some("abc is first")
case Array("xyz", _*) => Some("xyz is first")
case _ => None
} match {
case Some(x) => x
case _ => "Either empty or incorrect first entry"
}
虽然以下编译良好:
(x match {
case Array("abc", _*) => Some("abc is first")
case Array("xyz", _*) => Some("xyz is first")
case _ => None
}) match {
case Some(x) => x
case _ => "Either empty or incorrect first entry"
}
为什么后面的版本(第一个匹配表达式在括号中)编译得很好,而早期的版本却没有?