How does Java step by step evaluate something like this step by step?

Possible duplicate:
What are the rules for evaluation order in Java?

a = f(b) * - d + e++ + f(e)

Just wondering how this will go in stages, and where can I find the rules for this?


source to share

1 answer

SECOND EDIT: My answer appears to be wrong, see Adam Liss's link in the comments to the question (now moved to the question itself, see Possible Duplicate). I leave my answer here for the details that Niklas provided along with my (incorrect) answer to see what prompted the comments.

If I am not mistaken, the evaluation tree is built according to operator precedence order and then evaluated accordingly. The method call should be the first thing to evaluate, since return values ​​may be required in the expression.

EDIT: The estimate (assuming the sums are indeed evaluated from left to right) would look like this (the "intermediate value" called t is the current value after each step):

evaluate f(b)
calculate t = f(b) - d
calculate t = t + e      (since it e++ and not ++e)
evaluate e++
evaluate f(e)
calculate t = t + f(e)
assignment a = t




All Articles