August 2004
Intermediate to advanced
480 pages
9h 41m
English
What happens when a value of one type is converted to a wider type—that is, a type with a wider range of possible values. Converting from a short to an int is a widening conversion; converting from a char to a byte is not. The Java runtime knows that your variable couldn't suffer any loss of data by putting its value in a container bigger than the one it already has. For this reason, widening conversions happen automatically. You can lose data when performing a widening conversion that is done automatically. Numerical range is the important thing. Example (float's numerical range encompasses long's, but long (64-bits) can hold more digits than float (32-bits)):
public class ConversionTest { public static void main(String[] ...Read now
Unlock full access