test/tools/javac/lambda/LambdaConv09.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/LambdaConv09.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,50 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *  check that SAM conversion handles Object members correctly
     1.9 + * @author  Alex Buckley
    1.10 + * @author  Maurizio Cimadamore
    1.11 + * @compile/fail/ref=LambdaConv09.out -XDrawDiagnostics LambdaConv09.java
    1.12 + */
    1.13 +
    1.14 +class LambdaConv09 {
    1.15 +
    1.16 +    // Not a SAM type; not enough abstract methods
    1.17 +    interface Foo1 {}
    1.18 +
    1.19 +    // SAM type; Foo has no abstract methods
    1.20 +    interface Foo2 { boolean equals(Object object); }
    1.21 +
    1.22 +
    1.23 +    // Not a SAM type; Foo still has no abstract methods
    1.24 +    interface Foo3 extends Foo2 { public abstract String toString(); }
    1.25 +
    1.26 +    // SAM type; Bar has one abstract non-Object method
    1.27 +    interface Foo4<T> extends Foo2 { int compare(T o1, T o2); }
    1.28 +
    1.29 +    // Not a SAM type; still no valid abstract methods
    1.30 +    interface Foo5 {
    1.31 +        boolean equals(Object object);
    1.32 +        String toString();
    1.33 +    }
    1.34 +
    1.35 +    // SAM type; Foo6 has one abstract non-Object method
    1.36 +    interface Foo6<T> {
    1.37 +        boolean equals(Object obj);
    1.38 +        int compare(T o1, T o2);
    1.39 +    }
    1.40 +
    1.41 +    // SAM type; Foo6 has one abstract non-Object method
    1.42 +    interface Foo7<T> extends Foo2, Foo6<T> { }
    1.43 +
    1.44 +    void test() {
    1.45 +        Foo1 f1 = ()-> { };
    1.46 +        Foo2 f2 = ()-> { };
    1.47 +        Foo3 f3 = x -> true;
    1.48 +        Foo4 f4 = (x, y) -> 1;
    1.49 +        Foo5 f5 = x -> true;
    1.50 +        Foo6 f6 = (x, y) -> 1;
    1.51 +        Foo7 f7 = (x, y) -> 1;
    1.52 +    }
    1.53 +}

mercurial