Why is =+ (equals plus) valid in Apex?
Just fixed an unfortunate bug. I was trying to concatenate a string. But it kept getting replaced by the string it should have been adding. Couldn't figure it out for a while.
I was doing the operation like this:
attendeesListFormatted =+ attendeeFormated;
Took me a while to see my dyslexic mistake. Then I wondered why is that valid? Wouldn't it encounter an unexpected character after the assignment?
Then it occurred to me that maybe Apex was treating it as a null concatenation. Like so:
attendeesListFormatted = '' + attendeeFormated;
Can anyone think of another reason my mistake wouldn't throw an #error!
That is exactly what it is:
Integer i; i += 1;
This gives dereference null object #error!
i =+ 1;
i is now equal to one.
I cannot find this documented in the Salesforce Operators documentation though.