Bitwise AND (&) expression in Java -
I am debugging the code in which the expr1 & amp; Expr2
where there is a side effect of expr1
which affects the expr2
evaluation result I suspect that expr2
is defined as Expr1 is evaluated before
, because JLS has & amp; Amp; Guarantees the right-to-value assessment for
, but not necessarily & amp;
. I also suspect that changes in evaluation order may be the result of optimization by hotspot (we are running Java 6u20) do you know that hotspot can do such optimization? Better yet, provide an indication for documentation that thanks in advance to support or eliminate suspicion.
EDIT: Thank you for suggesting the code to re-write, so it's both right and readable - you're right, but I've already done it, so it's not what I'm looking for . Unfortunately, it is difficult to test changes, which is why I am asking questions here.
Assessment order is well defined:
Java programming language Guarantees that operators of operators are evaluated in a specific evaluation order, i.e. from left to right.
The hotspot adapter should not be optimized, which results in XPR 2 evaluation before Expr1. If this result changes, then this is a bug.
Note also says:
It is recommended that the code is not trusted on this specification not important.
Your code can be explicitly rewritten as follows:
int a = expr1; Int b = expr2; Full results = A & amp; B;
Comments
Post a Comment