1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
Starting in Java 9, the resource in a try-with-resources statement can be a
reference to a `final` or effectively-`final` variable.
That is, you can write this:
```java
AutoCloseable resource = ...;
try (resource) {
doSomething(resource);
}
```
instead of this:
```java
AutoCloseable resource = ...;
try (AutoCloseable resource2 = resource) {
doSomething(resource2);
}
```
NOTE: the resource cannot be an arbitrary expression, for example `try
(returnsTheResources()) { ... }` is still not allowed.
|