优化 if (admitTradeTypeVO.getAdmitType().equals("0")) { return "主动准入制"; } else if (admitTradeTypeVO.getAdmitType().equals("1")) { return "申请准入制"; } else if(admitTradeTypeVO.getAdmitType().equals("2")){ return "其他准入制"; } else { return ""; }
时间: 2023-04-04 15:02:57 浏览: 50
这段代码可以使用 switch 语句进行优化,如下所示:
switch (admitTradeTypeVO.getAdmitType()) {
case "0":
return "主动准入制";
case "1":
return "申请准入制";
case "2":
return "其他准入制";
default:
return "";
}
相关问题
优化这段代码if (admitTradeTypeVO != null) { if (admitTradeTypeVO.getAdmitType().equals("0")) { return "主动准入制"; } else if (admitTradeTypeVO.getAdmitType().equals("1")) { return "申请准入制"; } else if(admitTradeTypeVO.getAdmitType().equals("2")){ return "其他准入制"; } else { return ""; } } else { return ""; }
这段代码可以进行简化,可以使用switch语句代替多个if-else语句,如下所示:
switch (admitTradeTypeVO != null ? admitTradeTypeVO.getAdmitType() : "") {
case "0":
return "主动准入制";
case "1":
return "申请准入制";
case "2":
return "其他准入制";
default:
return "";
}
if (fragmentName.equals("B"))
This is a conditional statement that checks whether the value of the variable "fragmentName" is equal to the string "B". If it is, the code block inside the if statement will be executed. If not, the code block will be skipped.
相关推荐
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)