6
Reading some references it was possible to understand the basic, but not enough to decipher the following code:
public class Expression {
public static void main(String[] args) {
int s = 5;
s += s + mx(s) + ++s + s;
}
static int mx(int s) {
for (int i = 0; i < 3; i++) {
s = s + i;
}
return s;
}
}
Translated explanation
First, the left operand (assignment) is evaluated to produce a variable: In this case without mystery, as it is the
s
;Evaluation error may occur on both sides, which interrupts the evaluation: But this is not the case;
Then the right operand is evaluated and produces a value: here the explanation is very summarized, not making clear the way the value is produced;
Doubts
- What happens at each step of executing the expression?
- Operands are considered individually or the increment is valid for the next operand, for example?
Very intriguing question! :)
– gato