jdk-24/langtools/test/tools/javac/TryWithResources/ResDeclOutsideTry.java
Jan Lahoda a2b0a2413e 7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
Allowing final variables as operands to try-with-resources; also reviewed by Sergei Pikalev.

Reviewed-by: darcy, mcimadamore, vromero
2014-11-19 13:46:04 +01:00

24 lines
534 B
Java

/*
* @test /nodynamiccopyright/
* @bug 8025113
* @author sogoel
* @summary Resources cannot be declared outside t-w-r block
* @compile/fail/ref=ResDeclOutsideTry.out -XDrawDiagnostics ResDeclOutsideTry.java
*/
public class ResDeclOutsideTry implements AutoCloseable {
ResDeclOutsideTry tr1;
ResDeclOutsideTry tr2 = new ResDeclOutsideTry();
String test1() {
try (tr1 = new ResDeclOutsideTry(); tr2;) {
}
return null;
}
@Override
public void close() throws Exception {
}
}