Skip to content

Instantly share code, notes, and snippets.

@911992
Created July 2, 2020 21:25
Show Gist options
  • Save 911992/60b5997223c09850456cf3b66d71ac4b to your computer and use it in GitHub Desktop.
Save 911992/60b5997223c09850456cf3b66d71ac4b to your computer and use it in GitHub Desktop.
java try-with-resources AutoCloseable example
/*@author https://github.com/911992*/
class My_Closeable_Type implements AutoCloseable
{
public static void main (String arg_args[])
{
try(My_Closeable_Type _ins = new My_Closeable_Type()){
}/*will call close() automatically*/
}
@Override public void close(){/*mind there is no exception in signature, so no need for catch*/
System.out.println("Statement point 0");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment