[wp_ad_camp_1]
When comparing primitive numeric values and the two operands are not of the same type, the smaller one is promoted to the higher type.
For example,
1 2 3 | if( 6f >= 6) { System.out.println(true); } |
The value 6f
is of type float
; while 6
is of type int
.
During the comparison, 6
is promoted to float
because 6f
is of type float
. The type int
is the smaller type; while the type float
is the larger type.
Internally, Java compares 2 float
values.
[wp_ad_camp_2]
1 2 3 | if( 6f >= 6f) { System.out.println(true); } |
This rule is based on Java Numeric Promotion rules.
Another example,
1 2 3 4 | short s = 6; if( 6 >= s) { System.out.println(true); } |
Here, we have 6
of int
type and another 6
of short
type. The type int
is the larger type now; while the short
type is the smaller type.
Internally, the comparison will be between 2 int
values.
1 2 3 4 | short s = 6; if( 6 >= (int)s) { System.out.println(true); } |
[wp_ad_camp_3]
So, is there a way to prove or trace this promotion programmatically? Nope, as far as I know.