Baz
Baz

Reputation: 13175

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.

Upvotes: 13

Views: 4037

Answers (3)

AlexWien
AlexWien

Reputation: 28767

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().

Upvotes: 2

James Van Huis
James Van Huis

Reputation: 5571

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.

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272417

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.

e.g. see the code for ObjectOutputStream.flush()

Upvotes: 16

Related Questions