1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/lambdaExpression/EffectivelyFinal_neg.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,25 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 8003280 1.7 + * @summary Add lambda tests 1.8 + * Negative test of capture of "effectively final" local variable in lambda expressions 1.9 + * @compile/fail/ref=EffectivelyFinal_neg.out -XDrawDiagnostics EffectivelyFinal_neg.java 1.10 + */ 1.11 + 1.12 +public class EffectivelyFinal_neg { 1.13 + 1.14 + void test() { 1.15 + String s = "a"; 1.16 + String s2 = "a"; 1.17 + int n = 1; 1.18 + ((Runnable) 1.19 + ()-> { 1.20 + s2 = "b"; //re-assign illegal here 1.21 + System.out.println(n); 1.22 + System.out.println(s); 1.23 + s = "b"; // not effectively final 1.24 + } 1.25 + ).run(); 1.26 + n = 2; // not effectively final 1.27 + } 1.28 +}