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

it2022-05-08  6

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){

}

转载于:https://www.cnblogs.com/lpthread/p/3410036.html


最新回复(0)