jdk-24/test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.java
Joe Darcy bf2d27c5a4 8219254: Update explicit uses of latest source/target in langtools tests to a property
8219256: Update javac diags tests to use properties

Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Reviewed-by: jjg, jlahoda, darcy, iignatyev
2019-02-21 10:29:16 -08:00

38 lines
1.1 KiB
Java

/*
* @test /nodynamiccopyright/
* @bug 8206986
* @summary Check types inferred for switch expressions.
* @compile/fail/ref=ExpressionSwitchInfer.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchInfer.java
*/
import java.util.ArrayList;
import java.util.List;
public class ExpressionSwitchInfer {
private static final String NULL = "null";
private <T> T test(List<T> l, Class<T> c, String param) {
test(param == NULL ? new ArrayList<>() : new ArrayList<>(), CharSequence.class, param).charAt(0);
test(param == NULL ? new ArrayList<>() : new ArrayList<>(), CharSequence.class, param).substring(0);
test(switch (param) {
case NULL -> new ArrayList<>();
default -> new ArrayList<>();
}, CharSequence.class, param).charAt(0);
test(switch (param) {
case NULL -> new ArrayList<>();
default -> new ArrayList<>();
}, CharSequence.class, param).substring(0);
String str = switch (param) {
case "" -> {
break 0;
} default ->"default";
};
return null;
}
}