简体   繁体   中英

The flush method of OutputStream does nothing?

From OutputStream.flush() docs.

Why does it state here in the doc that the flush method of OutputStream does nothing after explaining that it actually does something? Very confusing.

OutputStream is an abstract class to be derived from. Subclasses will provide their own implementation if necessary . Otherwise the default behaviour is to do nothing.

eg see the code for ObjectOutputStream.flush()

OutputStream is an abstract class. The deriving instance has to override that, if it needs a flush. For example the BufferedOutputStream .
Streams that have no buffer may not need to override flush() .

The first part of the text is describing the general contract of flush . Classes which extend OutputStream are expected to adhere to this contract.

OutputStream is an abstract class, but a default implementation of flush is provided. As described, the implementation does nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM