For some inexplicable reason the byte
primitive type is signed in Java. This mean that valid values are -128..127 instead of the usual 0..255 range representin
byte, short, char
types are mostly useless, except when used in arrays to save space.
Neither Java or JVM has any real support for them. Almost all operations on them will promote them to int
or long
first. We cannot even write something like
short a=1, b=2;
a = a + b; // illegal
a = a << 1; // illegal
Then why the heck even bother with defining operations on byte, short, char
types at all?
All they do are sneaking in widening conversions that will surprise the programmer.