There is no += method, it is expanded to x = x + 1 by the compiler. This is detailed in the specification:
6.12.4 Assignment Operators
Let's consider an assignment operator such as += in an infix operation l += r, where l, r
are expressions. This operation can be re-interpreted as an operation which corresponds to the assignment
l = l + r
except that the operation's left-hand-side l is evaluated only once.
The re-interpretation occurs if the following two conditions are fulfilled.
The left-hand-side l does not have a member named +=, and also cannot be converted by an implicit conversion to a value with a member named +=.
The assignment l = l + r is type-correct. In particular this implies that l refers to a variable or object that can be assigned to, and that is convertible to a value with a member named +.
5+=1to actually do? I don't know Scala, but I don't see any reason for it to allow you to overwrite a primitive's value...