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

Java example source code file (MethodReference28.java)

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

integer, methodreference28::m2, methodreference28::m3, methodreference28\:\:m1, methodreference28\:\:m4, methodreference28\:\:static_m1, methodreference28\:\:static_m2, methodreference28\:\:static_m3, methodreference28\:\:static_m4, sam1, sam2

The MethodReference28.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that non-compatible method references are rejected
 * @compile/fail/ref=MethodReference28.out -XDrawDiagnostics MethodReference28.java
 */

class MethodReference28 {

    interface SAM1 {
        void m(int i);
    }

    interface SAM2 {
        void m(MethodReference28 rec, int i);
    }

    static void static_m1(Integer i) { } //ok - boxing
    static void static_m2(Integer i1, Integer i2) { } //wrong arity
    static void static_m3(String s) { } //type mismatch
    static void static_m4(String... ss) { } //type mismatch - varargs

    void m1(Integer i) { } //ok - boxing
    void m2(Integer i1, Integer i2) { } //wrong arity
    void m3(String s) { } //type mismatch
    void m4(String... ss) { } //type mismatch - varargs

    static void testStatic() {
        SAM1 s1 = MethodReference28::static_m1;
        SAM1 s2 = MethodReference28::static_m2;
        SAM1 s3 = MethodReference28::static_m3;
        SAM1 s4 = MethodReference28::static_m4;
    }

    void testBadMember() {
        SAM1 s1 = MethodReference28::m1;
        SAM1 s2 = MethodReference28::m2;
        SAM1 s3 = MethodReference28::m3;
        SAM1 s4 = MethodReference28::m4;
    }

    void testMember() {
        SAM1 s1 = this::m1;
        SAM1 s2 = this::m2;
        SAM1 s3 = this::m3;
        SAM1 s4 = this::m4;
    }

    static void testUnbound() {
        SAM2 s1 = MethodReference28::m1;
        SAM2 s2 = MethodReference28::m2;
        SAM2 s3 = MethodReference28::m3;
        SAM2 s4 = MethodReference28::m4;
    }
}

Other Java examples (source code examples)

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