File: MethodReference28.java

package info (click to toggle)
openjdk-25 25.0.1%2B8-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 825,408 kB
  • sloc: java: 5,585,680; cpp: 1,333,948; xml: 1,321,242; ansic: 488,034; asm: 404,003; objc: 21,088; sh: 15,106; javascript: 13,265; python: 8,319; makefile: 2,518; perl: 357; awk: 351; pascal: 103; exp: 83; sed: 72; jsp: 24
file content (56 lines) | stat: -rw-r--r-- 1,599 bytes parent folder | download | duplicates (19)
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
/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that non-compatible method references are rejected
 * @compile/fail/ref=MethodReference28.out -XDrawDiagnostics MethodReference28.java
 */

class MethodReference28 {

    interface SAM1 {
        void m(int i);
    }

    interface SAM2 {
        void m(MethodReference28 rec, int i);
    }

    static void static_m1(Integer i) { } //ok - boxing
    static void static_m2(Integer i1, Integer i2) { } //wrong arity
    static void static_m3(String s) { } //type mismatch
    static void static_m4(String... ss) { } //type mismatch - varargs

    void m1(Integer i) { } //ok - boxing
    void m2(Integer i1, Integer i2) { } //wrong arity
    void m3(String s) { } //type mismatch
    void m4(String... ss) { } //type mismatch - varargs

    static void testStatic() {
        SAM1 s1 = MethodReference28::static_m1;
        SAM1 s2 = MethodReference28::static_m2;
        SAM1 s3 = MethodReference28::static_m3;
        SAM1 s4 = MethodReference28::static_m4;
    }

    void testBadMember() {
        SAM1 s1 = MethodReference28::m1;
        SAM1 s2 = MethodReference28::m2;
        SAM1 s3 = MethodReference28::m3;
        SAM1 s4 = MethodReference28::m4;
    }

    void testMember() {
        SAM1 s1 = this::m1;
        SAM1 s2 = this::m2;
        SAM1 s3 = this::m3;
        SAM1 s4 = this::m4;
    }

    static void testUnbound() {
        SAM2 s1 = MethodReference28::m1;
        SAM2 s2 = MethodReference28::m2;
        SAM2 s3 = MethodReference28::m3;
        SAM2 s4 = MethodReference28::m4;
    }
}