test/tools/javac/lambda/TargetType24.java

changeset 1415
01c9d4161882
child 2000
4a6acc42c3a1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/TargetType24.java	Sat Nov 17 19:01:03 2012 +0000
     1.3 @@ -0,0 +1,39 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8003280
     1.7 + * @summary Add lambda tests
     1.8 + *  check case of nested method calls with lambda expression
     1.9 + * @compile/fail/ref=TargetType24.out -XDrawDiagnostics TargetType24.java
    1.10 + */
    1.11 +
    1.12 +class TargetType24 {
    1.13 +
    1.14 +    interface F<A, B> {
    1.15 +        B f(A a);
    1.16 +    }
    1.17 +
    1.18 +    interface FSub<A, B> extends F<A,B> { }
    1.19 +
    1.20 +    static class Array<A> {
    1.21 +        boolean forAll(final F<A, Boolean> f) {
    1.22 +            return false;
    1.23 +        }
    1.24 +
    1.25 +        String forAll(final FSub<A, String> f) {
    1.26 +            return "";
    1.27 +        }
    1.28 +
    1.29 +        String forAll2(final FSub<A, String> f) {
    1.30 +            return "";
    1.31 +        }
    1.32 +    }
    1.33 +
    1.34 +    void test(Array<String> as, final Array<Character> ac) {
    1.35 +        final boolean b1 = as.forAll(s -> ac.forAll(c -> false)); //ok
    1.36 +        final String s1 = as.forAll2(s -> ac.forAll2(c -> "")); //ok
    1.37 +        final boolean b2 = as.forAll(s -> ac.forAll(c -> "" )); //fail
    1.38 +        final String s2 = as.forAll2(s -> ac.forAll2(c -> false)); //fail
    1.39 +        final boolean b3 = as.forAll((F<String, Boolean>)s -> ac.forAll((F<Character, Boolean>)c -> "")); //fail
    1.40 +        final String s3 = as.forAll((FSub<String, String>)s -> ac.forAll((FSub<Character, String>)c -> false)); //fail
    1.41 +    }
    1.42 +}

mercurial