aboutsummaryrefslogtreecommitdiff
path: root/test/tools/javac/lambda/MethodReference22.java
blob: 094ef8936e5c067bc5850645bc8cff87863c73c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that pair of bound/non-bound method references checked correctly
 * @author  Maurizio Cimadamore
 * @compile/fail/ref=MethodReference22.out -XDrawDiagnostics MethodReference22.java
 */

class MethodReference22 {

    void m1(String x) { }
    void m1(MethodReference22 rec, String x) { }

    static void m2(String x) { }
    static void m2(MethodReference22 rec, String x) { }

    static void m3(String x) { }
    void m3(MethodReference22 rec, String x) { }

    void m4(String x) { }
    static void m4(MethodReference22 rec, String x) { }

    interface SAM1 {
        void m(String x);
    }

    interface SAM2 {
        void m(MethodReference22 rec, String x);
    }

    static void call1(SAM1 s) {   }

    static void call2(SAM2 s) {   }

    static void call3(SAM1 s) {   }
    static void call3(SAM2 s) {   }

    static void test1() {
        SAM1 s1 = MethodReference22::m1; //fail
        call1(MethodReference22::m1); //fail
        SAM1 s2 = MethodReference22::m2; //ok
        call1(MethodReference22::m2); //ok
        SAM1 s3 = MethodReference22::m3; //ok
        call1(MethodReference22::m3); //ok
        SAM1 s4 = MethodReference22::m4; //fail
        call1(MethodReference22::m4); //fail
    }

    static void test2() {
        SAM2 s1 = MethodReference22::m1; //ok
        call2(MethodReference22::m1); //ok
        SAM2 s2 = MethodReference22::m2; //ok
        call2(MethodReference22::m2); //ok
        SAM2 s3 = MethodReference22::m3; //fail
        call2(MethodReference22::m3); //fail
        SAM2 s4 = MethodReference22::m4; //fail
        call2(MethodReference22::m4); //fail
    }

    static void test3() {
        call3(MethodReference22::m1); //ok
        call3(MethodReference22::m2); //ambiguous
        call3(MethodReference22::m3); //ok
        call3(MethodReference22::m4); //fail
    }
}