As javadoc says, you don't need to flush yourself. But, this is still good to do, given your readers and common sense.
Few experts know hawadok by heart. I would not know for sure whether the stream would turn red or not without looking at it, and I'm probably not alone. Observing an explicit call to flush() makes this very clear, and therefore makes code reading easier.
In addition, the name of the close() method does not say anything about flushing. It is from the Closeable interface and, of course, it says nothing about flushing. If you do not flush the buffer output before closing, even though it wanted to flush it, you will rely on assumptions that may or may not be true. This will weaken your implementation.
Any assumptions you have made, you must somehow move on to future attendants. One way to do this is to leave a comment:
// no need to flush() manually, close() will do it automatically
If you do not leave this comment, future maintainers may have to look for javadoc too, if, like me, they are not remembered. But then, why are you writing such a comment when it is easier and better to just call it now and do with it.
In short, flushing before closing just follows good logic first. Assumptions and assumptions are not necessary, and readers need not be forced to think.
janos source share