Consider this function:
public static final int F(int a, int b) {
a = a - 1 + b;
// and some stuff
return a;
}
Is it required for implementations of JVMs to execute - 1
before + b
?
If we have a system profiler attached to the JVM, will we see the + b
operation being carried out before the + 1
operation?
Actually, I will disagree with the rest of the answers. The JLS §15.7 that people are referring to discusses the evaluation of operands. That is, in the expression
, in which order will the methods be invoked.
The relevant section is §15.7.3, which specifies
Since the expression
x = x - 1 + q
is equivalent in all ways tox = x + q - 1
, a conforming implementation is allowed to rewrite the expression (if it for some reason should decide that is more efficient).