Kotlin:if语句多余

时间:2018-09-23 00:43:54

标签: if-statement kotlin

我有此代码:

: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 } 将无法再到达以下

1 个答案:

答案 0 :(得分:7)

fx1 > eachSideBesidesFace

是布尔值语句。您不需要if-else:

val leftEnoughRoom = fx1 > eachSideBesidesFace

作为旁注,您可以单击带下划线的表达式,然后按Alt + Enter,然后让Android Studio自动优化代码。