Bra*_*son 0 java conditional variable-assignment
我正在寻找一种更有效的方法来执行以下操作,我将方法的返回值附加到数组.但是,如果返回为null,我想执行另一个操作而不是更改数组.
Object[] myVal = new Object[10];
Object temp;
temp = myFunction();
if(temp != null) {
myVal[count++] = temp;
} else {
System.Exit();
}
Run Code Online (Sandbox Code Playgroud)
我想在一个方法的返回值中指定一个变量,但是如果返回的值为null,则提供"内联"检查以执行另一个操作.
就像是:
myVal = (myFunction() != null) ? [output of expression]: System.Exit();
Run Code Online (Sandbox Code Playgroud)
有这样的方法吗?
myVal = myFunction();
if (myVal == null) System.exit(0);
Run Code Online (Sandbox Code Playgroud)
不需要临时变量.
| 归档时间: |
|
| 查看次数: |
872 次 |
| 最近记录: |