Skip to content

Instantly share code, notes, and snippets.

@tigawa
Last active December 19, 2015 21:49
Show Gist options
  • Save tigawa/6023287 to your computer and use it in GitHub Desktop.
Save tigawa/6023287 to your computer and use it in GitHub Desktop.
java7 クローズ処理を明示的に呼び出さない書き方
public class AutoClose {
public static void main(String[] args) {
try (AutoCloseable a = new AutoClose().new AutoCloseable()) {
System.out.print("A");
} catch (Exception e) {
System.out.print("B");
} finally {
System.out.print("C");
}
}
private class AutoCloseable implements java.lang.AutoCloseable {
public void close() throws Exception {
System.out.print("D");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment