Versions Compared

Key

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

Narrower primitive types can be cast to wider types without affecting the magnitude of numeric values. See JLS, Section 5.1.2, "Widening Primitive Conversion" for more information. Conversion from int or long to float, or long to double can lead to loss of precision (loss of least significant bits). No runtime exception occurs despite this loss. Also see guideline EXP05INT10-J. Be aware of integer promotions in binary operators.

Note that conversions from float to double can also lose information about the overall magnitude of the converted value. (See guideline FLP04-J. Use the strictfp modifier for floating point calculation consistency for additional information.)

...