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

Java example source code file (T8016177c.java)

This example Java source code file (T8016177c.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

extfunction, function, integer, t8016177c

The T8016177c.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8016081 8016178
 * @summary structural most specific and stuckness
 * @compile/fail/ref=T8016177c.out -XDrawDiagnostics T8016177c.java
 */

class T8016177c {

    interface Function<X, Y> {
        Y m(X x);
    }

    interface ExtFunction<X, Y> extends Function { }

    <U, V> U m1(Function f) { return null; }
    <U, V> U m1(ExtFunction f) { return null; }

    void m2(Function<Integer, Integer> f) { }
    void m2(ExtFunction<Integer, Integer> f) { }

    void m3(Function<Integer, Integer> f) { }
    void m3(ExtFunction<Object, Integer> f) { }

    int g1(Object s) { return 1; }

    int g2(Number s) { return 1; }
    int g2(Object s) { return 1; }

    void test() {
        m1((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
        m2((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
        m3((Integer x)->x); //ok - explicit lambda (only one applicable)

        m1(x->1); //ok - stuck lambda but nominal most specific wins
        m2(x->1); //ok - stuck lambda but nominal most specific wins
        m3(x->1); //ambiguous - implicit lambda & different params

        m1(this::g1); //ok - unambiguous ref - subtyping picks most specific
        m2(this::g1); //ok - unambiguous ref - subtyping picks most specific
        m3(this::g1); //ambiguous - both applicable, neither most specific

        m1(this::g2); //ok - stuck mref but nominal most specific wins
        m2(this::g2); //ok - stuck mref but nominal most specific wins
        m3(this::g2); //ambiguous - different params
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java T8016177c.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.