Versions Compared

Key

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

...

Also, see EXP04-J. Be wary of invisible implicit casts when using compound assignment operators and EXP05-J. Be careful of autoboxing when removing elements from a Collection.

Noncompliant Code Example

In this noncompliant code example, the statement big * one carries out a binary operation. As big is an int and one is of type float, big is promoted to a float. This implicit cast results in loss of precision.

...

The output produced is 2.0E9 whereas, the expected output is 1.999999999E9.

Compliant solution

In this case, a double should be used instead of a float for a safe widening primitive conversion caused by integer promotion.

...