Widening Primitive Conversion
When a smaller type is converted to a bigger type:
- byte to short, int, long, float, or double
- short to int, long, float, or double
- char to int, long, float, or double
- int to long, float, or double
- long to float or double
- float to double
A widening primitive conversion does not lose information about the overall magnitude of a numeric value.
Narrowing Primitive Conversion
When a bigger type is converted to a smaller type
- short to byte or char
- char to byte or short
- int to byte, short, or char
- long to byte, short, char, or int
- float to byte, short, char, int, or long
- double to byte, short, char, int, long, or float
A narrowing primitive conversion may lose information about the overall magnitude of a numeric value
Combined Widening and Narrowing Primitive Conversion
The following conversion combines both widening and narrowing primitive conversions:
- byte to char
First, the byte is converted to an int via widening primitive conversion, and then the resulting int is converted to a char by narrowing primitive conversion
|
|