5.6.1 Unary Numeric Promotion

Some operators apply unary numeric promotion to a single operand, which must produce a value of a numeric type:

Unary numeric promotion is performed on expressions in the following situations:

Here is a test program that includes examples of unary numeric promotion:


class Test {
	public static void main(String[] args) {
		byte b = 2;
		int a[] = new int[b];							// dimension expression promotion
		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 test program produces the output:


a: -1,1
~0xffffffff==0x0
0xffffffff<<4L==0xfffffff0