Are there any real life uses for the Java byte primitive type?
Posted
by
Thorbjørn Ravn Andersen
on Stack Overflow
See other posts from Stack Overflow
or by Thorbjørn Ravn Andersen
Published on 2011-07-31T21:31:18Z
Indexed on
2012/03/28
5:29 UTC
Read the original article
Hit count: 148
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 representing 8 significant bits in a byte (without a sign bit).
This mean that all byte manipulation code usually does integer calculations and end up masking out the last 8 bits.
I was wondering if there is any real life scenario where the Java byte
primitive type fits perfectly or if it is simply a completely useless design decision?
EDIT: The sole actual use case was a single-byte placeholder for native code. In other words, not to be manipulated as a byte inside Java code.
© Stack Overflow or respective owner