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

Java example source code file (MethodRef_neg.java)

This example Java source code file (MethodRef_neg.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, methodref_neg\:\:bar, methodref_neg\:\:make, string

The MethodRef_neg.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *   This is negative test for wrong parameter/return type in method references
 * @compile/fail/ref=MethodRef_neg.out -XDrawDiagnostics MethodRef_neg.java
 */

public class MethodRef_neg {

    static interface A {void m(Integer i);}

    static interface B {void m(String s);}

    static interface C {Integer m();}

    static interface D {String m();}


    static void bar(int x) { }

    int foo() {
        return 5;
    }

    static void make() { }

    void method() {
        A a = MethodRef_neg::bar; //boxing on parameter type is ok
        B b = MethodRef_neg::bar; //wrong parameter type, required: String, actual: int
        C c = this::foo; //boxing on return type is ok
        D d = this::foo; //wrong return type, required: String, actual: int
        a = MethodRef_neg::make; //missing parameter
        c = MethodRef_neg::make; //missing return type
    }
}

Other Java examples (source code examples)

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