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:
Automatic Conversions |
---|
|
"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.
Recall (from chapter 8) that float
has only about
seven decimal digits of precision.
For example, converting the int
123456789 to
the float
123456700.0 shows a loss of precision
(but is done, anyway).
Will there be a loss of precision in converting
the int
123456789 to
the double
?