Can someone clarify the rules for switching on a variable smaller than an int.
I know that we can only switch on byte, short, int or char. But what if we switch on say a byte:
byte byt = 17;
switch (byt) {
case 17:
System.out.println("17");
break;
case 120:
System.out.println("120");
break;
case 250:
System.out.println("250");
break;
}
The case 250 gives a loss of precission compile time error.
I thought
java might promote the byte to an int.
and then then
test like so:
if (byt == 250) System.out.println("250");
Which is legal. Could any of you ranchers clarify the actual rules for switch statements.