Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

why int as return type in read() not char.  RSS feed

 
Parmeet Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
public int read() throws IOException;

read() in java.io.Reader returns int, and to print it we have to cast it to char.

why not this method can have return type char instead of int.

one point can be it returns -1 in case no char exist thats why it returns int, but that can not be a sole reason as it leads to cast an output every time we read a char. may be million times in some big file.

Please assist.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question to more than one forum; see our explanation here. I'm closing this copy.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!