This content has been marked as final. Show 3 replies
They are not equivalent.
is equivalent to:
byte b = 0; b += 100;
byte b = 0; b = (byte)(b + 100);
this is valid for numberics (int, double, float, etc.). For byte you need to cast for compile but adding bytes is usually senseless as you usually add nummbers (or strings) and then you should use the corresponding types.
This behavior is well defined in the JLS (Java Language Specification). The pertinent JLS section (15.25.2 Compound Assignment Operators) can be found at http://java.sun.com/docs/books/jls/first_edition/html/15.doc.html#5304