由于return
方法体中存在关键字,SonarQube 刚刚将以下表达式评估为代码异味。但是,如果我删除return
IntelliJ 会警告一个无用的表达式。
条件如下。
if (map.contains("numProperties")) {
if (map("numProperties").toInt >= 20)
return true
return false
}
true
Run Code Online (Sandbox Code Playgroud)
这可能是你想要的:
map.get("numProperties").forall(_.toInt >= 20)
Run Code Online (Sandbox Code Playgroud)
Theget
返回 an Option
,如果为空或对内容的测试返回,则调用forall
an返回。Option
true
Option
true
保持原来的形式是:
if (map.contains("numProperties")) {
if (map("numProperties").toInt >= 20) {
true
} else {
false
}
} else {
true
}
Run Code Online (Sandbox Code Playgroud)