aboutsummaryrefslogtreecommitdiff
path: root/test/tools/javac/lambda/TargetType60.java
blob: b5acd32d17b927e56029bfab0e88233c38d8fa97 (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
/*
 * @test /nodynamiccopyright/
 * @bug 8007462
 * @summary Fix provisional applicability for method references
 * @compile/fail/ref=TargetType60.out -XDrawDiagnostics TargetType60.java
 */
class TargetType60 {

    interface Sam0 {
        void m();
    }

    interface Sam1<X> {
        void m(X x);
    }

    interface Sam2<X,Y> {
        void m(X x, Y y);
    }

    void m0() { }
    void m1(String s) { }
    void m2(String s1, String s2) { }

    void m01() { }
    void m01(String s) { }

    void m012() { }
    void m012(String s) { }
    void m012(String s1, String s2) { }

    void n0() { }
    void n1(String s) { }
    void n2(TargetType60 rec, String s2) { }

    void n01() { }
    void n01(String s) { }

    void n012() { }
    void n012(String s) { }
    void n012(TargetType60 rec, String s2) { }

    static String g(Sam0 s) { return null; }
    static <U> U g(Sam1<U> s) { return null; }
    static <U> U g(Sam2<U,String> s) { return null; }

    static <U> U u(Sam1<U> s) { return null; }
    static <U> U u(Sam2<U,String> s) { return null; }

    void testBound() {
        String s1 = g(this::m0); //ok - resolves to g(Sam0)
        String s2 = g(this::m1); //ok - resolves to g(Sam1)
        String s3 = g(this::m2); //ok - resolves to g(Sam2)
        String s4 = g(this::m01);//ambiguous (g(Sam0), g(Sam1) apply)
        String s5 = g(this::m012);//ambiguous (g(Sam0), g(Sam1), g(Sam2) apply)
    }

    static void testUnbound() {
        TargetType60 s1 = u(TargetType60::n0); //ok - resolves to u(Sam1)
        TargetType60 s2 = u(TargetType60::n1); //ok - resolves to u(Sam2)
        TargetType60 s3 = u(TargetType60::n2); //none is applicable
        TargetType60 s4 = u(TargetType60::n01);//ambiguous (u(Sam1), u(Sam2) apply)
        TargetType60 s5 = u(TargetType60::n012);//ambiguous (u(Sam1), u(Sam2) apply)
    }
}