test/tools/javac/lambda/MethodReference51.java

changeset 1415
01c9d4161882
child 2193
d4cbb671de1c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/MethodReference51.java	Sat Nov 17 19:01:03 2012 +0000
     1.3 @@ -0,0 +1,46 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *  certain cases of erroneous member reference lookup are not handled by Attr.visitReference
     1.9 + * @compile/fail/ref=MethodReference51.out -XDrawDiagnostics MethodReference51.java
    1.10 + */
    1.11 +class MethodReference51 {
    1.12 +
    1.13 +    private static class Foo {
    1.14 +        static int j(int i) { return i; }
    1.15 +    }
    1.16 +
    1.17 +    static Foo foo = new Foo();
    1.18 +
    1.19 +    static void m(String s) { }
    1.20 +    static void m(Integer i) { }
    1.21 +
    1.22 +    static int f(String s) { return 1; }
    1.23 +
    1.24 +    static int g(Integer i, Number n) { return 1; }
    1.25 +    static int g(Number n, Integer i) { return 1; }
    1.26 +
    1.27 +    int h(int i) { return i; }
    1.28 +}
    1.29 +
    1.30 +class TestMethodReference51 {
    1.31 +
    1.32 +    interface IntSam {
    1.33 +        int m(int i);
    1.34 +    }
    1.35 +
    1.36 +    interface IntegerIntegerSam {
    1.37 +        int m(Integer i1, Integer i2);
    1.38 +    }
    1.39 +
    1.40 +
    1.41 +    static void test() {
    1.42 +        IntSam s1 = MethodReference51::unknown; //method not found
    1.43 +        IntSam s2 = MethodReference51::f; //inapplicable method
    1.44 +        IntSam s3 = MethodReference51::g; //inapplicable methods
    1.45 +        IntegerIntegerSam s4 = MethodReference51::g; //ambiguous
    1.46 +        IntSam s5 = MethodReference51::h; //static error
    1.47 +        IntSam s6 = MethodReference51.foo::j; //inaccessible method
    1.48 +    }
    1.49 +}

mercurial