On 22/04/2020 13:50, Andrew Haley wrote:
:
1. Should close() always be idempotent, where practical? I would have
    thought so, but perhaps there are downsides.

2. Should classes which implement close() with the standard meaning be
    AutoCloseable?

I'm sure Joe Darcy can say more on this but I remember there was a lot of effort put into this topic when AutoCloseable was added in Java 7 (and Project Coin). Closeable close is idempotent but AutoCloseable close could not require it. AutoCloseable's API docs recommend it of course. There was effort in Java 7 and beyond to retrofit existing classes that defined a close method to be Closeable or AutoCloseable. There are only a handful of exported APIs remaining that have a close method that don't extend or implement AutoCloseable. I don't know the history of the XML stream interface to know why they close to define them not to close the underlying stream but I doubt these could be changed now.

-Alan.

Reply via email to