我想了解三元運算符,並沒有看到與返回語句的例子。閱讀和理解三元操作符?
return (next == null) ? current : reversing(current,next);
如果沒有三元運算符,你會怎麼寫?難道僅僅是:
if (next == null) {
} else {
return (current,next);
我想了解三元運算符,並沒有看到與返回語句的例子。閱讀和理解三元操作符?
return (next == null) ? current : reversing(current,next);
如果沒有三元運算符,你會怎麼寫?難道僅僅是:
if (next == null) {
} else {
return (current,next);
號你可以寫成如下
if (next == null) {
return current;
} else {
return reversing(current, next);
}
您的版本:
if (next == null) {
return current;
} else {
return reversing(current,next);
}
也就是說,else
是沒有必要的。我把上null
早日迴歸自身:
if (next == null) {
return current;
}
return reversing(current, next);
return (next == null) ? current : reversing(current, next);
相當於
if (next == null) {
return current;
} else {
return reversing(current, next);
}
*沒有看到收益報表爲例*爲什麼會影響運作? –
請參閱文檔http://stackoverflow.com/documentation/java/118/basic-control-structures/2806/ternary-operator#t=201703021604546865206 – basslo