[Java]try-with-resource (AutoCloseable)


[Java]try-with-resource (AutoCloseable)

Java try-with-resource (AutoCloseable) - AutoCloseable 인터페이스 - 자동 자원 해제 대상 - JDK 7 버전 이전 자원 해제 - JDK 7 버전 이후 자원 해제 - AutoCloseable 구현 AutoCloseable 인터페이스 AutoCloseable 인터페이스는 JDK 7 버전에 등장하였고, AutoCloseable을 상속받고 있는 구현체가 try-with-resources 구문안에서 선언된 객체들에 대해서 자동으로 자원을 해제(Close)해주는 기능을 제공한다. try-with-resources 문장으로 관리되는 객체에 대해서 자동으로 close() 처리한다. InterruptedException을 던지지 않도록 하는 것을 권장한다. InterruptedException은 쓰레드의 인터럽트 상태와 상호작용하므로 InterruptedException이 억제되었을 때 런타임에서 잘못된 동작이 발생할 수 있다. // try-with-re...


#AutoCloseable #Closeable

원문링크 : [Java]try-with-resource (AutoCloseable)