gpt4 book ai didi

scala - 是否可以对变量使用 match scala 操作?

转载 作者:行者123 更新时间:2023-12-05 09:24:59 28 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
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
}

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