2

Java 7 特性具有资源自动关闭多捕获语句,但在这两种情况下它如何在内部工作?

例如

// Try with resource
public void testTryWithResourcesStatement() throws FileNotFoundException, IOException {
    try (FileInputStream in = new FileInputStream("java7.txt")) {
        System.out.println(in.read());
    }
}

这里不需要finally。但它在内部如何运作?JVM如何在内部关闭它?

4

0 回答 0