问题描述
可能显示的文件:结果
Why的确不是Java已经有条件和和条件,或运营商的复合赋值版本? (安培;&安培; =,= ||)结果
今天,在工作中我写了下面LOC(b和B1真正的身份是保密的:)
Today at work I wrote the following LOC (the real identities of b and b1 are confidential :)
b &&= b1; // meaning b = b && b1;
我盯着它几秒钟,意识到存在这样的操作符。为了保险起见,我点击编译和失败。是死肯定我咨询的标准。
I stared at it for a couple of seconds and realized that there exists no such operator. Just to be sure, I clicked on compile and it failed. To be dead sure I consulted the standard.
有没有,有没有这样的运营商具体的原因是什么?我能想到的一些:
Are there specific reasons that there are no such operators? I can think of some:
-
B和;&安培; = B1
和B = B和;&安培; B1
可能不是等效的,因为短路评价和放大器;&安培; - &放大器;&安培; =丑
- &放大器;&安培; =很少用到
b &&= b1
andb = b && b1
may not be equivalent because of short-circuit evaluation of &&.- &&= is ugly
- &&= is rarely needed
我并不认为这将是有这样的运营商非常有用的,没有。我也并不认为任何或所有上述三个原因是不够的,从创建操作者不要。我的问题是:?是有可能发生更严重的原因,对此我监督
I do not claim that it would be very useful to have such operators, no. I also don't claim that any or all of the three above reasons are not enough to refrain from creating that operator. My question is the following: is there maybe a much more serious reason which I am overseeing?
推荐答案
我不知道为什么这两个问题,一些问题的答案提相应的逻辑运算符的短路行为作为一个潜在的问题。
I don't know why both the question and some of the answers mention short-circuiting behavior of the corresponding logical operators as a potential issue.
有绝对没有短路有关的问题,界定&放大器;&安培; =
和 || =
运营商。他们应该均匀地 + =
和其他类似的运营商来定义,这意味着 A和&安培; = B
应相当于 A = A和&安培; b
,但 A
正在&放大器只计算一次;&安培; =
版本。这又意味着, B
不计算在所有如果 A
原本是为零。很简单。
There's absolutely no short-circuit-related problems with defining &&=
and ||=
operators. They should be defined uniformly with +=
and other similar operators, meaning that a &&= b
should be equivalent to a = a && b
, but with a
being evaluated only once in &&=
version. This means in turn that b
is not evaluated at all if a
is originally zero. Easy.
所以,唯一的原因,他们没有在语言是存在的,那么,只是因为
So, the only reason they don't exist in the language is, well, "just because".
这篇关于&功放;&安培; =和|| =操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!