test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.java
changeset 51563 de411d537aae
child 53023 6879069d9d94
equal deleted inserted replaced
51562:1b1bca603244 51563:de411d537aae
       
     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 12 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 }