File: LambdaConv09.java

package info (click to toggle)
openjdk-11 11.0.16%2B8-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 784,576 kB
  • sloc: java: 5,128,021; xml: 1,192,224; cpp: 1,124,021; ansic: 422,433; javascript: 155,577; sh: 17,084; objc: 13,327; python: 4,522; asm: 3,570; makefile: 2,858; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (50 lines) | stat: -rw-r--r-- 1,369 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
/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that SAM conversion handles Object members correctly
 * @author  Alex Buckley
 * @author  Maurizio Cimadamore
 * @compile/fail/ref=LambdaConv09.out -XDrawDiagnostics LambdaConv09.java
 */

class LambdaConv09 {

    // Not a SAM type; not enough abstract methods
    interface Foo1 {}

    // SAM type; Foo has no abstract methods
    interface Foo2 { boolean equals(Object object); }


    // Not a SAM type; Foo still has no abstract methods
    interface Foo3 extends Foo2 { public abstract String toString(); }

    // SAM type; Bar has one abstract non-Object method
    interface Foo4<T> extends Foo2 { int compare(T o1, T o2); }

    // Not a SAM type; still no valid abstract methods
    interface Foo5 {
        boolean equals(Object object);
        String toString();
    }

    // SAM type; Foo6 has one abstract non-Object method
    interface Foo6<T> {
        boolean equals(Object obj);
        int compare(T o1, T o2);
    }

    // SAM type; Foo6 has one abstract non-Object method
    interface Foo7<T> extends Foo2, Foo6<T> { }

    void test() {
        Foo1 f1 = ()-> { };
        Foo2 f2 = ()-> { };
        Foo3 f3 = x -> true;
        Foo4 f4 = (x, y) -> 1;
        Foo5 f5 = x -> true;
        Foo6 f6 = (x, y) -> 1;
        Foo7 f7 = (x, y) -> 1;
    }
}