I read the byte stream and noticed the following statement
Note that read () returns an int value. If the input is a stream of bytes, why doesn't it read () returns the byte value? Using int as a return of type allows read () to use -1 to indicate that it has reached the goal of the stream.
The reason for use intis that they can identify an EOF of -1. (seems small)
So, the following is a simpler primitive type short, and it also supports -1, so why not use it?
From what I collect: (reasons to use int)
- Due to performance
intis preferred.
(this) intthe variable contains the character value in the last 16 bits (from the
character test )- Other more abstract streams would have to read more than one byte (something that I think (happens with character streams))
Are my reasons true? Am I missing something (e.g. error correction)?
source
share