集册 Java实例教程 实现AutoCloseable

实现AutoCloseable

欢马劈雪     最近更新时间:2020-01-02 10:19:05

495
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
实现AutoCloseable

public class _01SimpleTryWithResource {
/*
 from nowjava.com - 时代Java 
*/

  public static void main(String[] args) {

    try (Test test = new Test();) {

      test.show();

      // No Need to Call it

      // test.close();

    } catch (Exception e) {

      System.out.println(e.toString());

    } finally {

    }

  }


}


class Test implements AutoCloseable {
/** 来 自 n o w  j a v a  . c o m**/

  @Override

  public void close() throws Exception {

    System.out.println(
展开阅读全文