Skip to main content

Numeric Promotion

Numeric promotion is a Java concept. It promotes smaller data types to larger ones during arithmetic.

The conversion steps are added at compile time. This doesn't mean the result is known to be too large. The compiler just does a heuristic check. It sees if the result can fit in the smaller type.

Why is numeric promotion needed?

Numeric promotion is needed to prevent data loss during arithmetic operations. For example,

  • byte + byte is promoted to int. Adding two bytes can give a value past the byte range. It's promoted to int for the larger range.
  • int + long is promoted to long.
  • int + float is promoted to float.
  • int + double is promoted to double.
Numeric promotion follows a specific hierarchy

The hierarchy of numeric promotion in Java is as follows: byte → short → int → long → float → double