No, they’re different types, the operation needs to be normalized for one type, and it has to be one that all work well.
To string doesn’t work well with numbers, what number she would be to add up?
So all operands are considered as string and there’s only one concatenation and not one sum.
All Java types can be converted to string, although not always properly. Only a few strings can be converted into number and it is not the compiler’s job to check this, because most of the time he will not even know what the value is.
This is because of the association and precedence of operators (in this case the precedence does not matter because it is the same operator in all sub-expressions). That’s what it’s doing:
x + " "
whose result is
"0 "
Then he takes this result as the left operator and makes a new "sum" with the right operand:
"0 " + y
whose result is
"0 1"
Then he takes this result and finally makes the last sum:
"0 1" + z
whose result is
"0 12"
I put in the Github for future reference.
Associativity is always left to right in this operator (there are operators that is reversed)
On all sums you’re using one string with a number.
Thank you, I can understand why
– Alberto