1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8206986
4 * @summary Check types inferred for switch expressions.
5 * @compile/fail/ref=ExpressionSwitchInfer.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchInfer.java
6 */
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 public class ExpressionSwitchInfer {
12
13 private static final String NULL = "null";
14
15 private <T> T test(List<T> l, Class<T> c, String param) {
16 test(param == NULL ? new ArrayList<>() : new ArrayList<>(), CharSequence.class, param).charAt(0);
17 test(param == NULL ? new ArrayList<>() : new ArrayList<>(), CharSequence.class, param).substring(0);
18
19 test(switch (param) {
20 case NULL -> new ArrayList<>();
21 default -> new ArrayList<>();
22 }, CharSequence.class, param).charAt(0);
23 test(switch (param) {
24 case NULL -> new ArrayList<>();
25 default -> new ArrayList<>();
|
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8206986
4 * @summary Check types inferred for switch expressions.
5 * @compile/fail/ref=ExpressionSwitchInfer.out -XDrawDiagnostics ExpressionSwitchInfer.java
6 */
7
8 import java.util.ArrayList;
9 import java.util.List;
10
11 public class ExpressionSwitchInfer {
12
13 private static final String NULL = "null";
14
15 private <T> T test(List<T> l, Class<T> c, String param) {
16 test(param == NULL ? new ArrayList<>() : new ArrayList<>(), CharSequence.class, param).charAt(0);
17 test(param == NULL ? new ArrayList<>() : new ArrayList<>(), CharSequence.class, param).substring(0);
18
19 test(switch (param) {
20 case NULL -> new ArrayList<>();
21 default -> new ArrayList<>();
22 }, CharSequence.class, param).charAt(0);
23 test(switch (param) {
24 case NULL -> new ArrayList<>();
25 default -> new ArrayList<>();
|