Hey, I have the following two lines of code:
result[i] = temp[i] + temp[i + 1] + " " + temp[i + 2];
i += 2;
I am wondering if this line of code would do the same:
result[i] = temp[i] + temp[i++] + " " + temp[i++];
Can I be sure, that EVERY VM would process the line from the left to the right? Thanks, Tobi
From Java language specification:
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.
It is recommended that code not rely crucially on this specification. Code is usually clearer when each expression contains at most one side effect, as its outermost operation, and when code does not depend on exactly which exception arises as a consequence of the left-to-right evaluation of expressions.
It should be
result[i] = temp[i] + temp[++i] + " " + temp[++i];
if I am not wrong, so that the indexes are computed after each incrementation. Apart from that it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With