所有,
我是Scala的新手。我想实现以下逻辑:
def func(): Boolean = {
var a = true
val b = "for some condition checking"
if (b == "some value") {
a = false
}
a
}
如果我不想使用“var”,我可能会这样写吗?
def func(): Boolean = {
val b = "for some condition checking"
if (b == "some value") {
false
}
true
}
Scala中有更好的实现吗?非常感谢提前!
答案 0 :(得分:2)
怎么样:
def func(): Boolean = {
val b = "for some condition checking"
b != "some value"
}