JDK7中的新特性 The try-with-resources Statement
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
类似于这样的代码
try ( ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos)); ) { oos.writeUnshared(attributes); oos.flush(); serialized = bos.toByteArray(); }
简而言之就是不用自己费事写finally啦, 可以避免finally里面再出exception导致try里的exception被覆盖的问题