Why does InputStream#read() return an int and not a byte?

user489041 picture user489041 · Jan 11, 2011 · Viewed 11.2k times · Source

Why does InputStream#read() return an int and not a byte?

Answer

BalusC picture BalusC · Jan 11, 2011

Because a byte can only hold -128 until 127, while it should return 0 until 255 (and -1 when there's no byte left (i.e. EOF)). Even if it returned byte, there would be no room to represent EOF.

A more interesting question is why it doesn't return short.