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