test/tools/javac/lambda/LambdaConv09.java

changeset 0
959103a6100f
equal deleted inserted replaced
-1:000000000000 0:959103a6100f
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 */
10
11 class LambdaConv09 {
12
13 // Not a SAM type; not enough abstract methods
14 interface Foo1 {}
15
16 // SAM type; Foo has no abstract methods
17 interface Foo2 { boolean equals(Object object); }
18
19
20 // Not a SAM type; Foo still has no abstract methods
21 interface Foo3 extends Foo2 { public abstract String toString(); }
22
23 // SAM type; Bar has one abstract non-Object method
24 interface Foo4<T> extends Foo2 { int compare(T o1, T o2); }
25
26 // Not a SAM type; still no valid abstract methods
27 interface Foo5 {
28 boolean equals(Object object);
29 String toString();
30 }
31
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 }
37
38 // SAM type; Foo6 has one abstract non-Object method
39 interface Foo7<T> extends Foo2, Foo6<T> { }
40
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 }

mercurial