Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8003280
4 * @summary Add lambda tests
5 * check that SAM conversion handles Object members correctly
6 * @author Alex Buckley
7 * @author Maurizio Cimadamore
8 * @compile/fail/ref=LambdaConv09.out -XDrawDiagnostics LambdaConv09.java
9 */
11 class LambdaConv09 {
13 // Not a SAM type; not enough abstract methods
14 interface Foo1 {}
16 // SAM type; Foo has no abstract methods
17 interface Foo2 { boolean equals(Object object); }
20 // Not a SAM type; Foo still has no abstract methods
21 interface Foo3 extends Foo2 { public abstract String toString(); }
23 // SAM type; Bar has one abstract non-Object method
24 interface Foo4<T> extends Foo2 { int compare(T o1, T o2); }
26 // Not a SAM type; still no valid abstract methods
27 interface Foo5 {
28 boolean equals(Object object);
29 String toString();
30 }
32 // SAM type; Foo6 has one abstract non-Object method
33 interface Foo6<T> {
34 boolean equals(Object obj);
35 int compare(T o1, T o2);
36 }
38 // SAM type; Foo6 has one abstract non-Object method
39 interface Foo7<T> extends Foo2, Foo6<T> { }
41 void test() {
42 Foo1 f1 = ()-> { };
43 Foo2 f2 = ()-> { };
44 Foo3 f3 = x -> true;
45 Foo4 f4 = (x, y) -> 1;
46 Foo5 f5 = x -> true;
47 Foo6 f6 = (x, y) -> 1;
48 Foo7 f7 = (x, y) -> 1;
49 }
50 }