What will this program write to the monitor?
New location:java.awt.Point[x=12,y=42]
In general, if there is the possibility that information will be LOST, a conversion between one type and another will NOT be performed automatically. A conversion from a data type that uses N bits to a type that uses fewer than N bits risks information loss, and will not be performed automatically. The compiler makes this decision by examining the data types involved, not the actual values involved.
In the following situations, the compiler will automatically convert from the type of the expression in a method call to the required type:
"Loss of precision" means that some of the less significant digits may become zeros, but the most important digits and the size of the number will remain. For example 123456789 converted to 123456700.0 shows a loss of precision.
In the following situations, the compiler will not automatically perform the conversion.
Remember the sizes of the various primitive types (the primitive types char and boolean are not listed here):
type | number of bits |
---|---|
byte | 8 |
short | 16 |
int | 32 |
long | 64 |
float | 32 |
double | 64 |