1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/funcInterfaces/LambdaTest1_neg3.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,19 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 8003280 1.7 + * @summary Add lambda tests 1.8 + * This test is to verify mis-use of capturing local variable within lambda expression 1.9 + * @compile/fail/ref=LambdaTest1_neg3.out -XDrawDiagnostics LambdaTest1_neg3.java 1.10 + */ 1.11 + 1.12 +public class LambdaTest1_neg3 { 1.13 + void method() { 1.14 + int n = 2; //effectively final variable 1.15 + ((Runnable) 1.16 + ()-> { 1.17 + int n2 = n; //inside lambda accessing effectively final variable; 1.18 + } 1.19 + ).run(); 1.20 + n++; //compile error if n is modified 1.21 + } 1.22 +}