Why does InputStream read() return an int and not a short?
java
Solution
The most important reason to prefer `int` over `short` is that `short` is kind of a second-class citizen: all integer literals, as well as all arithmetical operations, are `int`-typed so you've got `short`->`int` promotion happening all over the place. Plus there is very little or no argument against the usage of `int`.
Problem
I was reading the byte stream trial and noticed the following statement Notice that read() returns an int value. If the input is a stream of bytes, why doesn't read() return a byte value? Using a int as a return type allows read() to use -1 to indicate that it has reached the end of the stream. The given reason for using an `int` is that they can identify EOF by a -1. (seems shallow) So the next bigger primitive type is `short` and it also supports -1 so why not use it? From what i gather: (reasons to use `int`) - Due to performance `int` is preferred. (this) - `int` variable holds a character value in its last 16 bits (from character trial) - Other more abstract streams would need to read more than just one byte (something that i guess (happens with character streams)) Are my reasons correct? Am i missing something (like error correction)?