Ok, as of Java 6 there is no y literal suffix. Consider this code:
byte b = some_byte();
switch (b) {
case (byte) 0x80: ...
case (byte) 0x81: ...
and this alternative:
int b = some_byte() & 0xff;
switch (b) {
case 0x80: ...
case 0x81: ...
Which would you use? In the first case, are (byte) casts performed during run time or compile time? Thanks.
Probably the latter, just for simplicity – but with a comment to explain what’s going on.
Compile-time. Don’t forget that case values have to be compile-time constants anyway.
Another option is to create constants for these things:
private static final byte FOO = (byte) 0x80;
private static final byte BAR = (byte) 0x81;
Aside from anything else, that makes the values less “magic”.
Or you could possibly even use an enum…