test/tools/javac/lambda/TargetType24.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/TargetType24.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,42 @@
     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((String s) -> ac.forAll((Character c) -> false)); //ok
    1.36 +        final boolean b2 = as.forAll(s -> ac.forAll(c -> false)); //ambiguous
    1.37 +        final boolean b3 = as.forAll((String s) -> ac.forAll(c -> false)); //ambiguous
    1.38 +        final boolean b4 = as.forAll(s -> ac.forAll((Character c) -> false)); //ambiguous
    1.39 +        final String s1 = as.forAll2(s -> ac.forAll2(c -> "")); //ok
    1.40 +        final boolean b5 = as.forAll(s -> ac.forAll(c -> "" )); //fail
    1.41 +        final String s2 = as.forAll2(s -> ac.forAll2(c -> false)); //fail
    1.42 +        final boolean b6 = as.forAll((F<String, Boolean>)s -> ac.forAll((F<Character, Boolean>)c -> "")); //fail
    1.43 +        final String s3 = as.forAll((FSub<String, String>)s -> ac.forAll((FSub<Character, String>)c -> false)); //fail
    1.44 +    }
    1.45 +}

mercurial