When a value (or variable) of one numeric type is assigned to a variable of another numeric type, the new type may hold a bigger number or smaller maximum number. If the target type can hold a bigger number, the conversion is widening. If otherwise, it is a narrowing conversion, which usually requires a typecasting using a cast operator.
Widening and narrowing conversion of primitive types
Widening
The maximum number a numeric type can hold is determined by the number of bits allocated to this type. To remind you, here is the number of bits for each numeric type representation:
- byte: 8 bit
- char: 16 bit
- short: 16 bit
- int: 32 bit
- long: 64 bit
- float: 32 bit
- double: 64 bit
The Java Specification defines 19 widening primitive...