Replies: 4 comments
-
try-with-resources 구문은 AutoCloseable 인터페이스가 구현된 클래스의 자원을 자동으로 해제하는 데 사용된다. 주로 파일이나 데이터베이스 연결과 같은 자원을 사용하는 경우에 많이 활용된다. 또한, try () 괄호 안에 여러 개의 리소스를 선언하고 초기화할 수 있고, 예외가 발생하면 catch 블록으로 제어가 전달되는데, 이때 리소스가 안전하게 해제된다. |
Beta Was this translation helpful? Give feedback.
-
외부의 리소스는 사용하면 닫아주는 것이 중요합니다. 이처럼 사용 후, 반납해야 하는 자원을 try-with-resource로 관리할 수 있습니다. try-with-resource가 없던 시절에는 직접 자원을 닫아줘야 했는데요,
try-with-resource는 이런 문제들을 해결해줄 수 있는 좋은 수단입니다. |
Beta Was this translation helpful? Give feedback.
-
https://tecoble.techcourse.co.kr/post/2021-04-26-try-with-resource/ |
Beta Was this translation helpful? Give feedback.
-
자원 자동 반납 |
Beta Was this translation helpful? Give feedback.
-
그리고 왜 나왔을까요!?
Beta Was this translation helpful? Give feedback.
All reactions