Java Reference
In-Depth Information
char c = '\u0001';
a[c] = 1; // index expression promotion
a[0] = -c; // unary - promotion
System.out.println("a: " + a[0] + "," + a[1]);
b = -1;
int i = ~b; // bitwise complement promotion
System.out.println("~0x" + Integer.toHexString(b)
+ "==0x" + Integer.toHexString(i));
i = b << 4L; // shift promotion (left operand)
System.out.println("0x" + Integer.toHexString(b)
+ "<<4L==0x" + Integer.toHexString(i));
}
}
This program produces the output:
a: -1,1
~0xffffffff==0x0
0xffffffff<<4L==0xfffffff0
5.6.2. Binary Numeric Promotion
When an operator applies binary numeric promotion to a pair of operands, each of which
must denote a value that is convertible to a numeric type, the following rules apply, in or-
der:
1. If any operand is of a reference type, it is subjected to unboxing conversion
5.1.8 ) .
2. Widening primitive conversion (§ 5.1.2 ) is applied to convert either or both oper-
ands as specified by the following rules:
• If either operand is of type double , the other is converted to double .
• Otherwise, if either operand is of type float , the other is converted to float .
• Otherwise, if either operand is of type long , the other is converted to long .
• Otherwise, both operands are converted to type int .
After the type conversion, if any, value set conversion (§ 5.1.13 ) is applied to each operand.
Binary numeric promotion is performed on the operands of certain operators:
• The multiplicative operators * , / and % 15.17 )
• The addition and subtraction operators for numeric types + and - 15.18.2 )
• The numerical comparison operators < , <= , > , and >= 15.20.1 )
Search WWH ::




Custom Search