the*_*ava 2 javascript java switch-statement
function checkValue(value) {
if (value === null || value === undefined || value === '') {
return '-';
} else {
switch (value) {
case true:
return 'Yes';
break;
case false:
return 'No';
break;
default:
return value;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道按字符串切换的情况只有> 1.7.无论如何我可以在不使用传统的java中转换这段代码if/else.这段代码是用来写的JavaScript.
使用枚举代替<1.7开关字符串不支持
private enum MyEnum {
a, b, c, d;
}
String val; // input
MyEnum mye = MyEnum.valueOf(val);
switch (mye) {
case a:
return something;
case carrot:
return something;
..
}
Run Code Online (Sandbox Code Playgroud)
PS:伪代码.IDE不在手.抱歉.
| 归档时间: |
|
| 查看次数: |
323 次 |
| 最近记录: |