File: LambdaConv09.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 65,320 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
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;
    }
}