Net-informations.com
SiteMap  | About    

Numeric promotion in Java

Numeric promotion also known as Implicit casting or java automatic conversions where conversion of a smaller numeric type value to a larger numeric type automatically, so that integer and floating-point operations may take place. In numerical promotion , byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

In the above case, int i is promoted to double so the calculation can be performed. In some ways, you can think of this is analogous to boxing , but boxing involves moving from a struct to an object that is from the stack to the heap. But, using the analogy does give an idea of the fact the integral value is being made into a floating point to perform the calculation.

Widening Primitive Conversion

19 specific conversions on primitive types are called the widening primitive conversions:

Narrowing Primitive Conversion

22 specific conversions on primitive types are called the narrowing primitive conversions:







net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.