Say we have a code like this:
int k=1;
System.out.println(k++ * ++k);
The output would be three and that’s what my question is about. Is it always the case that Java, instead of first reading the whole line and separating pre-instructions from post-instructions thus treating it as:
int k=1;
k+=1;
System.out.println(k*k);
k+=1;
…just reads from left to right? Or is it compiler-dependent and shouldn’t be relied upon?
This is defined operator by operator by the language specification. In the case of your first example, the rule for the
*operator is defined in JLS 15.17: