我有此代码:
:80
并得到警告:
val leftEnoughRoom = if(fx1 > eachSideBesidesFace){
true
}else{
false
}
它要我做什么?当我这样做时:
This inspection reports if statements which can be simplified to single statements. For example:
if (foo()) {
return true
} else {
return false
}
can be simplified to return foo().
然后,if(fx1 > eachSideBesidesFace){
val leftEnoughRoom = true
}else{
val leftEnoughRoom = false
}
将无法再到达以下
答案 0 :(得分:7)
fx1 > eachSideBesidesFace
是布尔值语句。您不需要if-else:
val leftEnoughRoom = fx1 > eachSideBesidesFace
作为旁注,您可以单击带下划线的表达式,然后按Alt + Enter,然后让Android Studio自动优化代码。