gpt4 book ai didi

Scala,如何访问整个匹配项 : X match {case Y(z) as matched =>

转载 作者:行者123 更新时间:2023-12-02 07:34:44 26 4
gpt4 key购买 nike

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

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

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

最佳答案

您应该能够使用@ 语法:

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

来自 here

关于Scala,如何访问整个匹配项 : X match {case Y(z) as matched =>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17982421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com