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 13 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<>(); 26 }, CharSequence.class, param).substring(0); 27 28 String str = switch (param) { 29 case "" -> { 30 break 0; 31 } default ->"default"; 32 }; 33 34 return null; 35 } 36 37 }