Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8003280
4 * @summary Add lambda tests
5 * check that code generation handles void-compatibility correctly
6 * @compile/fail/ref=LambdaConv21.out -XDrawDiagnostics LambdaConv21.java
7 */
9 class LambdaConv21 {
11 interface SAM_void<X> {
12 void m();
13 }
15 interface SAM_java_lang_Void {
16 Void m();
17 }
19 static void m_void() { }
21 static Void m_java_lang_Void() { return null; }
23 static void testExpressionLambda() {
24 SAM_void s1 = ()->m_void(); //ok
25 SAM_java_lang_Void s2 = ()->m_void(); //no - incompatible target
26 SAM_void s3 = ()->m_java_lang_Void(); //ok - expression statement lambda is compatible with void
27 SAM_java_lang_Void s4 = ()->m_java_lang_Void(); //ok
28 }
30 static void testStatementLambda() {
31 SAM_void s1 = ()-> { m_void(); }; //ok
32 SAM_java_lang_Void s2 = ()-> { m_void(); }; //no - missing return value
33 SAM_void s3 = ()-> { return m_java_lang_Void(); }; //no - unexpected return value
34 SAM_java_lang_Void s4 = ()-> { return m_java_lang_Void(); }; //ok
35 SAM_void s5 = ()-> { m_java_lang_Void(); }; //ok
36 SAM_java_lang_Void s6 = ()-> { m_java_lang_Void(); }; //no - missing return value
37 }
38 }