test/tools/javac/lambda/LambdaConv09.java

Tue, 12 Mar 2013 16:02:43 +0000

author
mcimadamore
date
Tue, 12 Mar 2013 16:02:43 +0000
changeset 1628
5ddecb91d843
parent 0
959103a6100f
permissions
-rw-r--r--

8009545: Graph inference: dependencies between inference variables should be set during incorporation
Summary: Move all transitivity checks into the incorporation round
Reviewed-by: jjg

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

mercurial