alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (TargetType24.java)

This example Java source code file (TargetType24.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

array, boolean, fsub, string, targettype24

The TargetType24.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check case of nested method calls with lambda expression
 * @compile/fail/ref=TargetType24.out -XDrawDiagnostics TargetType24.java
 */

class TargetType24 {

    interface F<A, B> {
        B f(A a);
    }

    interface FSub<A, B> extends F { }

    static class Array<A> {
        boolean forAll(final F<A, Boolean> f) {
            return false;
        }

        String forAll(final FSub<A, String> f) {
            return "";
        }

        String forAll2(final FSub<A, String> f) {
            return "";
        }
    }

    void test(Array<String> as, final Array ac) {
        final boolean b1 = as.forAll((String s) -> ac.forAll((Character c) -> false)); //ok
        final boolean b2 = as.forAll(s -> ac.forAll(c -> false)); //ambiguous
        final boolean b3 = as.forAll((String s) -> ac.forAll(c -> false)); //ambiguous
        final boolean b4 = as.forAll(s -> ac.forAll((Character c) -> false)); //ambiguous
        final String s1 = as.forAll2(s -> ac.forAll2(c -> "")); //ok
        final boolean b5 = as.forAll(s -> ac.forAll(c -> "" )); //fail
        final String s2 = as.forAll2(s -> ac.forAll2(c -> false)); //fail
        final boolean b6 = as.forAll((F<String, Boolean>)s -> ac.forAll((F)c -> "")); //fail
        final String s3 = as.forAll((FSub<String, String>)s -> ac.forAll((FSub)c -> false)); //fail
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java TargetType24.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.