小编Raj*_*pal的帖子

嵌套ifs在Java中使用Boolean的替代方法

我有下面的代码块

if(Objects.nonNull(isMine)) {
    if (isMine) {
             this.books= // gets it from the database;
    } else  {
            this. books= // gets it from the database
    }

 } else {
     this. books = // gets it from the database
 }
Run Code Online (Sandbox Code Playgroud)

isMine - 是一个布尔对象,我尝试使用switch case,将isMine转换为字符串,如下所示

 String.valueOf(isMine) 
Run Code Online (Sandbox Code Playgroud)

但是没有用.建议在java中实现上述代码的更好,更快的方法.

java collections if-statement switch-statement java-8

-2
推荐指数
1
解决办法
157
查看次数