2014-03-31

Java 7 introduced the AutoCloseable interface, which is roughly equivalent to the IDisposable interface of C#, to be used in synergy with the new try-with-resources statement, which is equivalent to the using-disposable construct of C#.

The problem with Java's AutoCloseable interface is that its close() method is declared to throw a checked exception: void close() throws Exception. This is a problem if you are one of the many programmers who prefer unchecked exceptions over checked ones, because it forces you to deal with checked exceptions every time you write a try-with-resources statement, despite the fact that none of your classes ever throw any checked exceptions on close(). Simply declaring that your class implements AutoCloseable forces checked exceptions upon you.