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

Java example source code file (LambdaConv21.java)

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

lambdaconv21, sam_java_lang_void, sam_void, void

The LambdaConv21.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that code generation handles void-compatibility correctly
 * @compile/fail/ref=LambdaConv21.out -XDrawDiagnostics LambdaConv21.java
 */

class LambdaConv21 {

    interface SAM_void<X> {
        void m();
    }

    interface SAM_java_lang_Void {
        Void m();
    }

    static void m_void() { }

    static Void m_java_lang_Void() { return null; }

    static void testExpressionLambda() {
        SAM_void s1 = ()->m_void(); //ok
        SAM_java_lang_Void s2 = ()->m_void(); //no - incompatible target
        SAM_void s3 = ()->m_java_lang_Void(); //ok - expression statement lambda is compatible with void
        SAM_java_lang_Void s4 = ()->m_java_lang_Void(); //ok
    }

    static void testStatementLambda() {
        SAM_void s1 = ()-> { m_void(); }; //ok
        SAM_java_lang_Void s2 = ()-> { m_void(); }; //no - missing return value
        SAM_void s3 = ()-> { return m_java_lang_Void(); }; //no - unexpected return value
        SAM_java_lang_Void s4 = ()-> { return m_java_lang_Void(); }; //ok
        SAM_void s5 = ()-> { m_java_lang_Void(); }; //ok
        SAM_java_lang_Void s6 = ()-> { m_java_lang_Void(); }; //no - missing return value
    }
}

Other Java examples (source code examples)

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