test/tools/javac/lambda/MethodReference23.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/MethodReference23.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,74 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *  check that pair of bound/non-bound constructor references is flagged as ambiguous
     1.9 + * @author  Maurizio Cimadamore
    1.10 + * @compile/fail/ref=MethodReference23.out -XDrawDiagnostics MethodReference23.java
    1.11 + */
    1.12 +
    1.13 +class MethodReference23 {
    1.14 +
    1.15 +    class Inner1 {
    1.16 +        Inner1(MethodReference23 outer) {};
    1.17 +        Inner1() {};
    1.18 +    }
    1.19 +
    1.20 +    static class Inner2 {
    1.21 +        Inner2(MethodReference23 outer) {};
    1.22 +        Inner2() {};
    1.23 +    }
    1.24 +
    1.25 +    interface SAM11 {
    1.26 +        Inner1 m(MethodReference23 rec);
    1.27 +    }
    1.28 +
    1.29 +    interface SAM12 {
    1.30 +        Inner1 m();
    1.31 +    }
    1.32 +
    1.33 +    interface SAM21 {
    1.34 +        Inner2 m(MethodReference23 rec);
    1.35 +    }
    1.36 +
    1.37 +    interface SAM22 {
    1.38 +        Inner2 m();
    1.39 +    }
    1.40 +
    1.41 +    static void call11(SAM11 s) {   }
    1.42 +
    1.43 +    static void call12(SAM12 s) {   }
    1.44 +
    1.45 +    static void call21(SAM21 s) {   }
    1.46 +
    1.47 +    static void call22(SAM22 s) {   }
    1.48 +
    1.49 +    static void call3(SAM11 s) {   }
    1.50 +    static void call3(SAM12 s) {   }
    1.51 +    static void call3(SAM21 s) {   }
    1.52 +    static void call3(SAM22 s) {   }
    1.53 +
    1.54 +    static void test11() {
    1.55 +        SAM11 s = MethodReference23.Inner1::new; //ok
    1.56 +        call11(MethodReference23.Inner1::new); //ok
    1.57 +    }
    1.58 +
    1.59 +    static void test12() {
    1.60 +        SAM12 s = MethodReference23.Inner1::new; //fail
    1.61 +        call12(MethodReference23.Inner1::new); //fail
    1.62 +    }
    1.63 +
    1.64 +    static void test21() {
    1.65 +        SAM21 s = MethodReference23.Inner2::new; //ok
    1.66 +        call21(MethodReference23.Inner2::new); //ok
    1.67 +    }
    1.68 +
    1.69 +    static void test22() {
    1.70 +        SAM22 s = MethodReference23.Inner2::new; //ok
    1.71 +        call22(MethodReference23.Inner2::new); //ok
    1.72 +    }
    1.73 +
    1.74 +    static void test3() {
    1.75 +        call3(MethodReference23.Inner2::new); //ambiguous
    1.76 +    }
    1.77 +}

mercurial