I aware that byte is not a proper type enough to contain result of read method.
So, read method returns int type value.
But i think a short type is more efficient type than int.
It could contain the value of range -256~ 255.
Why does read method return int, not short?
Java documentation on primitive types suggests that short
s should be used instead of int
s to "save memory in large arrays":
short
: Theshort
data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As withbyte
, the same guidelines apply: you can use ashort
to save memory in large arrays, in situations where the memory savings actually matters.
Since in this situation memory savings do not actually matter, using int
is a more consistent choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With