I expected to find XMLStreamReader to be AutoCloseable in Java 7. However, that is not the case. Is there a technical reason why StAX reader/writer interfaces were not (or should not be) retrofitted to implement AutoCloseable ? They already have close methods, whose intent is not different from the close method of AutoCloseable.
I expected to find XMLStreamReader to be AutoCloseable in Java 7. However, that is
Share
If you look closer to the
close()method ofAutoCloseable:Or even
Closeableclose()method :Whereas the
close()method ofXMLStreamReadersays :Indeed the input source is managed by the
Readerwhich implement theCloseableinterface. So it’s the reader that can be close in the try-with-ressource.For example :