Java AutoCloseable implement

Description

Java AutoCloseable implement

class MyResource implements AutoCloseable {
  public void close() {
    System.out.println("In MyResource?s close()");
  }//from  www  .j  a v  a2  s.  c  om
}

public class Main {
  public static void main(String args[]) throws Exception {
    try (MyResource mr = new MyResource()) {
      // ...
    } finally {
      System.out.println("In finally");
    }
  }
}



PreviousNext

Related