本文介绍了发现随机加号,没有语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在寻找了一些早期的code和发现,应该是一个语法错误,这种随机加号,但code工作得很好,我不知道为什么。

So, i was looking over some earlier code and found this random plus sign that should have been a syntax error, but the code worked fine and i don't get why

tv_distance.setText("Distance: " + 
        ( dist >= 1000 ? (String.format("%.1f", dist/1000f)) : +dist )
        + " " + metric );

额外加号是三元运算符的第三个操作数:

The extra plus sign is at the third operand of the ternary operator:

() ? () : +dist

所以我失去了什么?

So what am i missing?

推荐答案

DIST 是一个数字。在 + 只是指定的标志。例如, +5 总是相同的 5 ,但它是合法的。很显然,你更熟悉它的反面,如 -5

dist is a number. The + is just specifying the sign. For example, +5 is always the same as 5 but it is legal. Obviously, you're much more familiar with its opposite, as in -5.

这篇关于发现随机加号,没有语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:30