根据多个条件返回布尔值

xbw*_*lvn -3 java if-statement

我有一个用例,我想从函数返回布尔值

private boolean checkStatus(String param) {
  return param != null ?  randomBool() : true;
}

private boolean randomBool() {
  // return true or false on the basis of some condition 
}
Run Code Online (Sandbox Code Playgroud)

我收到了true关于声明的投诉问题。实现相同目标的另一种方法是什么?

声纳问题:应从表达式中删除冗余布尔文字以提高可读性。

Vol*_*ozo 6

只需将您的代码更改为下一个:

param == null || randomBool()
Run Code Online (Sandbox Code Playgroud)