O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

W
widening conversion

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[] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required