Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Java Language Specification (JLS) [JLS 2011], §5.6, "Numeric Promotions" [JLS 2011], " describes numeric promotion as the following:

...

Type coercion may occur when compound expressions are used with mixed operand types. Examples of compound assignment operators are +=, -=, *=, /=, &=, ^=, %=, <<=, >>=, >>>=, and |=.

According to the JLS, §15.26.2, "Compound Assignment Operators,"

...

Failing to consider integer promotions when dealing with floating-point and integer operands can result in loss of precision.

Bibliography

[Bloch 20052005a]

Puzzle 9, "Tweedledum"
Puzzle 31, "Ghost of Looper"

[Findbugs 2008]

"BIT: Bitwise OR of Signed Byte Value"

[JLS 2011]

§4.2.2, "Integer Operations"
§5.6, "Numeric Promotions"
§15.26.2, "Compound Assignment Operators"

...