In all books on Java, I've read that the compiler treats all whitespace in the same way and simply ignores extra whitespace, so it's best practice to use them liberally to improve code readability. I've found proof to that in every expression that I've written: It didn't matter whether there were spaces or not, and how many (or maybe I just didn't pay attention).
Recently I decided to experiment a little with operator precedence and associativity to test the precedence table in action and tried to compile
int a = 2;
int b = 3;
int c = a+++b;
int d = a+++++b;
While the former statement compiled perfectly, the latter produced an exception:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unexpected type. Required: variable. Found: value.
However, when I added spaces: int d = a++ + ++b
, it compiled. Why is this the case? Java is said to ignore extra whitespace anyway. (I have Java 8 and Netbeans IDE 8.2, if this matters.)
I guess this might have something to do with how expressions are parsed, but I'm not sure. I tried looking up several questions on parsing, whitespace, and operators on SO and on Google but couldn't find a definitive answer.
UPD. To address the comments that it's the 'extra' that matters, not all whitespace: since int c = a++ + b;
and int c=a+++b;
both compile, one could say, by analogy, that in int d = a ++ + ++b;
whitespace is 'extra' as well.