Java Reference
In-Depth Information
ing, not all types are compatible, and thus, not all type conversions are implicitly allowed.
For example, boolean and int are not compatible.
When one type of data is assigned to another type of variable, an automatic type conver-
sion will take place if
The two types are compatible.
The destination type is larger than the source type.
When these two conditions are met, a widening conversion takes place. For example, the
int type is always large enough to hold all valid byte values, and both int and byte are in-
teger types, so an automatic conversion from byte to int can be applied.
For widening conversions, the numeric types, including integer and floating-point types,
are compatible with each other. For example, the following program is perfectly valid since
long to double is a widening conversion that is automatically performed.
Although there is an automatic conversion from long to double , there is no automatic
conversion from double to long , since this is not a widening conversion. Thus, the follow-
ing version of the preceding program is invalid.
Search WWH ::




Custom Search