2

scala中是否有语法或方法可以访问case语句中的整个匹配结构?

为了澄清,如果有一个“as”关键字,可以这样做:

x match {
  case Y(z) as matched =>
    // do stuff both with "matched" and "z" here ...
  ...
}
4

1 回答 1

8

您应该能够使用以下@语法:

x match {
  case matched @ Y(z) =>
    // do stuff both with "matched" and "z" here ...
  ...
}

这里

于 2013-07-31T23:01:34.070 回答