test/tools/javac/lambda/MethodReference28.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/MethodReference28.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,56 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *  check that non-compatible method references are rejected
     1.9 + * @compile/fail/ref=MethodReference28.out -XDrawDiagnostics MethodReference28.java
    1.10 + */
    1.11 +
    1.12 +class MethodReference28 {
    1.13 +
    1.14 +    interface SAM1 {
    1.15 +        void m(int i);
    1.16 +    }
    1.17 +
    1.18 +    interface SAM2 {
    1.19 +        void m(MethodReference28 rec, int i);
    1.20 +    }
    1.21 +
    1.22 +    static void static_m1(Integer i) { } //ok - boxing
    1.23 +    static void static_m2(Integer i1, Integer i2) { } //wrong arity
    1.24 +    static void static_m3(String s) { } //type mismatch
    1.25 +    static void static_m4(String... ss) { } //type mismatch - varargs
    1.26 +
    1.27 +    void m1(Integer i) { } //ok - boxing
    1.28 +    void m2(Integer i1, Integer i2) { } //wrong arity
    1.29 +    void m3(String s) { } //type mismatch
    1.30 +    void m4(String... ss) { } //type mismatch - varargs
    1.31 +
    1.32 +    static void testStatic() {
    1.33 +        SAM1 s1 = MethodReference28::static_m1;
    1.34 +        SAM1 s2 = MethodReference28::static_m2;
    1.35 +        SAM1 s3 = MethodReference28::static_m3;
    1.36 +        SAM1 s4 = MethodReference28::static_m4;
    1.37 +    }
    1.38 +
    1.39 +    void testBadMember() {
    1.40 +        SAM1 s1 = MethodReference28::m1;
    1.41 +        SAM1 s2 = MethodReference28::m2;
    1.42 +        SAM1 s3 = MethodReference28::m3;
    1.43 +        SAM1 s4 = MethodReference28::m4;
    1.44 +    }
    1.45 +
    1.46 +    void testMember() {
    1.47 +        SAM1 s1 = this::m1;
    1.48 +        SAM1 s2 = this::m2;
    1.49 +        SAM1 s3 = this::m3;
    1.50 +        SAM1 s4 = this::m4;
    1.51 +    }
    1.52 +
    1.53 +    static void testUnbound() {
    1.54 +        SAM2 s1 = MethodReference28::m1;
    1.55 +        SAM2 s2 = MethodReference28::m2;
    1.56 +        SAM2 s3 = MethodReference28::m3;
    1.57 +        SAM2 s4 = MethodReference28::m4;
    1.58 +    }
    1.59 +}

mercurial