jdk/test/langtools/tools/javac/lambda/8294461/EffectivelyFinalLoopIncrement.java
2022-10-27 15:58:46 +00:00

15 lines
574 B
Java

/*
* @test /nodynamiccopyright/
* @summary Verify for() loop variable not effectively final even if loop never increments
* @bug 8294461
* @compile/fail/ref=EffectivelyFinalLoopIncrement.out -XDrawDiagnostics EffectivelyFinalLoopIncrement.java
*/
class EffectivelyFinalLoopIncrement {
EffectivelyFinalLoopIncrement() {
for (int i = 0; i < 10; i++) {
Runnable r = () -> System.out.println(i); // variable i is NOT effectively final
break; // even though "i++" is never reached
}
}
}