プログラミング言語Javaのtry-with-resources構文で用いるAutoClosable
インタフェース仕様では、close
メソッドのべき等(idempotent)性は要求されない。(実装時には"べき等"が強く推奨される)
void close() throws ExceptionCloses this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.
https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html#close--
(snip)
Note that unlike theclose
method ofCloseable
, thisclose
method is not required to be idempotent. In other words, calling thisclose
method more than once may have some visible side effect, unlikeCloseable.close
which is required to have no effect if called more than once. However, implementers of this interface are strongly encouraged to make theirclose
methods idempotent.
void close() throws IOExceptionCloses this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
https://docs.oracle.com/javase/8/docs/api/java/io/Closeable.html#close--
関連URL