我试图了解三元运算符,并且没有看到返回语句的示例。
return (next == null) ? current : reversing(current,next);
如果没有三元运算符,你会怎么写?它只是:
if (next == null) {
} else {
return (current,next);
答案 0 :(得分:5)
您的版本:
if (next == null) {
return current;
} else {
return reversing(current,next);
}
那就是说else
没有必要。我将null
的早期回报单独归结为:
if (next == null) {
return current;
}
return reversing(current, next);
答案 1 :(得分:3)
return (next == null) ? current : reversing(current, next);
相当于
if (next == null) {
return current;
} else {
return reversing(current, next);
}
答案 2 :(得分:2)
没有。你会写如下
if (next == null) {
return current;
} else {
return reversing(current, next);
}