"0xFF" is an int literal for the decimal value 255, which is not represented as a byte.
Now you need to pass it to byte to tell the compiler that you really mean -1, for example:
byte[] rawbytes = { 0xA, 0x2, (byte) 0xFF };
It was suggested to add a new byte literal syntax ( y or y suffix) in Java 7. Then you could write:
byte[] rawbytes = { 0xA, 0x2, 0xFFy };
However, this proposal was not included in the "omnibus proposal for improving integral literals", so we were stuck on the sheet forever.
erickson Aug 18 '10 at 19:47 2010-08-18 19:47
source share