1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8206986
4 * @summary Adding switch expressions
5 * @compile/fail/ref=BadSwitchExpressionLambda.out -XDrawDiagnostics --enable-preview -source 12 BadSwitchExpressionLambda.java
6 */
7
8 class BadSwitchExpressionLambda {
9
10 interface SAM {
11 void invoke();
12 }
13
14 public static void m() {}
15
16 void test(int i) {
17 SAM sam1 = () -> m(); //ok
18 SAM sam2 = () -> switch (i) { case 0 -> m(); default -> m(); }; //not ok
19 }
20 }
|
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8206986
4 * @summary Adding switch expressions
5 * @compile/fail/ref=BadSwitchExpressionLambda.out -XDrawDiagnostics --enable-preview -source 12 BadSwitchExpressionLambda.java
6 */
7
8 class BadSwitchExpressionLambda {
9
10 interface SAM {
11 void invoke();
12 }
13
14 public static void m() {}
15 public static void r(SAM sam) {}
16
17 void test(int i) {
18 SAM sam1 = () -> m(); //ok
19 SAM sam2 = () -> switch (i) { case 0 -> m(); default -> m(); }; //not ok
20 r(() -> m()); //ok
21 r(() -> switch (i) { case 0 -> m(); default -> m(); }); //not ok
22 return switch (i) { case 0 -> m(); default -> m(); }; //not ok
23 }
24 }
|