IDisposable in Java
Java 7 introduces an equivalent pattern to C#'s IDisposable pattern, AutoClosable, or try-with-resources. For example:
try (BufferedReader br = new
BufferedReader(new FileReader(path))) {
return br.readLine();
}
More info on the interface here: http://docs.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html
More info on usage here: http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
Prior to Java 7 you are unfortunately stuck with using standard try/finally and manually releasing resources.
Written by Mark McD ☠
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Idisposable
Authors
markm
10.14K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#