Java9でtry-with-resourcesの使い方

1.リソースの宣言
// A final resource
final Resource resource1 = new Resource(“resource1");
// An effectively final resource
Resource resource2 = new Resource(“resource2");

2.Java7とJava8で処理方法
// Original try-with-resources statement from JDK 7 or 8
try (Resource r1 = resource1;
Resource r2 = resource2) {
// Use of resource1 and resource 2 through r1 and r2.
}
3.Java9で処理方法
// New and improved try-with-resources statement in JDK 9
try (resource1;
resource2) {
// Use of resource1 and resource 2.
}

Java

Posted by arkgame