Java 7 新功能: 省略finally, 保证资源正常关闭

class MyResource implements Closeable{

    @Override

    public void close() throw IOException{

    }

}

 

try( myResource = new MyResource() ){    // no need to write finally block to release resource, java will automatially close this resource.

}catch(Exception e){

}

posted on 2013-11-06 11:00  lpthread  阅读(374)  评论(0编辑  收藏  举报