我想了解三元运算符,并没有看到与返回语句的例子。阅读和理解三元操作符?
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