1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/lambdaExpression/AccessNonStatic_neg.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,26 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 8003280 1.7 + * @summary Add lambda tests 1.8 + * Test accessing non-static variable from lambda expressions in static context 1.9 + * @compile/fail/ref=AccessNonStatic_neg.out -XDrawDiagnostics AccessNonStatic_neg.java 1.10 + */ 1.11 + 1.12 +public class AccessNonStatic_neg { 1.13 + 1.14 + private int n = 0; 1.15 + 1.16 + static { 1.17 + ((Runnable) ()-> { 1.18 + System.out.println(this); 1.19 + System.out.println(n); 1.20 + }).run(); 1.21 + } 1.22 + 1.23 + public static void test() { 1.24 + ((Runnable) ()-> { 1.25 + Object o = this; 1.26 + n++; 1.27 + }).run(); 1.28 + } 1.29 +}