test/tools/javac/lambda/BadAccess.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/BadAccess.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,30 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *  check that non-static variables are not accessible from static lambdas
     1.9 + * @author  Maurizio Cimadamore
    1.10 + * @compile/fail/ref=BadAccess.out -XDrawDiagnostics BadAccess.java
    1.11 + */
    1.12 +
    1.13 +public class BadAccess {
    1.14 +
    1.15 +    int i;
    1.16 +    static int I;
    1.17 +
    1.18 +    interface SAM {
    1.19 +        int m();
    1.20 +    }
    1.21 +
    1.22 +    static void test1() {
    1.23 +        int l = 0; //effectively final
    1.24 +        final int L = 0;
    1.25 +        SAM s = ()-> i + I + l + L;
    1.26 +    }
    1.27 +
    1.28 +    void test2() {
    1.29 +        int l = 0; //effectively final
    1.30 +        final int L = 0;
    1.31 +        SAM s = ()-> i + I + l + L;
    1.32 +    }
    1.33 +}

mercurial