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

Java example source code file (MethodReference22.java)

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

methodreference22::m3, methodreference22\:\:m1, methodreference22\:\:m2, methodreference22\:\:m4, sam1, sam2, string

The MethodReference22.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that pair of bound/non-bound method references checked correctly
 * @author  Maurizio Cimadamore
 * @compile/fail/ref=MethodReference22.out -XDrawDiagnostics MethodReference22.java
 */

class MethodReference22 {

    void m1(String x) { }
    void m1(MethodReference22 rec, String x) { }

    static void m2(String x) { }
    static void m2(MethodReference22 rec, String x) { }

    static void m3(String x) { }
    void m3(MethodReference22 rec, String x) { }

    void m4(String x) { }
    static void m4(MethodReference22 rec, String x) { }

    interface SAM1 {
        void m(String x);
    }

    interface SAM2 {
        void m(MethodReference22 rec, String x);
    }

    static void call1(SAM1 s) {   }

    static void call2(SAM2 s) {   }

    static void call3(SAM1 s) {   }
    static void call3(SAM2 s) {   }

    static void test1() {
        SAM1 s1 = MethodReference22::m1; //fail
        call1(MethodReference22::m1); //fail
        SAM1 s2 = MethodReference22::m2; //ok
        call1(MethodReference22::m2); //ok
        SAM1 s3 = MethodReference22::m3; //ok
        call1(MethodReference22::m3); //ok
        SAM1 s4 = MethodReference22::m4; //fail
        call1(MethodReference22::m4); //fail
    }

    static void test2() {
        SAM2 s1 = MethodReference22::m1; //ok
        call2(MethodReference22::m1); //ok
        SAM2 s2 = MethodReference22::m2; //ok
        call2(MethodReference22::m2); //ok
        SAM2 s3 = MethodReference22::m3; //fail
        call2(MethodReference22::m3); //fail
        SAM2 s4 = MethodReference22::m4; //fail
        call2(MethodReference22::m4); //fail
    }

    static void test3() {
        call3(MethodReference22::m1); //ok
        call3(MethodReference22::m2); //ambiguous
        call3(MethodReference22::m3); //ok
        call3(MethodReference22::m4); //fail
    }
}

Other Java examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.