(Note: I came across this somewhat accidentally, so it may not be practical, but I am just very curious)
I wanted to print out a value, which was the sum of two values, after incrementing the second. Something like so:
int first = 10;
int second = 20;
System.out.println(first + ++second); //31
System.out.println(first); //10
System.out.println(second); //21
Maybe not the neatest code, but it worked. But then, I started experimenting.
System.out.println(first +++ second); //30
System.out.println(first); //11
System.out.println(second); //21
That's fine; it means that the first was incremented after being added, and that whitespace can be ignored here. Cool. But then...
System.out.println(first +++++ second); //"Invalid Argument", doesn't work
While
System.out.println(first ++ + ++ second); //31
System.out.println(first); //11
System.out.println(second); //21
Works fine, but for some reason, is still different than
System.out.println(first + + + ++ second); //31
System.out.println(first); //10
System.out.println(second); //21
And maybe the strangest of all,
System.out.println(first + + + + + + second); //30
System.out.println(first); //10
System.out.println(second); //20
So what's going on here? When is whitespace between operators ignored, and when is it not? Why can I write "+ + + + +", without any issues?
Thanks!