jdk-24/test/langtools/tools/javac/switchexpr/ExpressionSwitchInfer.java
Jan Lahoda b34b2d993c 8223305: Compiler support for Switch Expressions
Reviewed-by: mcimadamore, vromero
2019-06-10 05:09:52 +02: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 "" -> {
yield 0;
} default ->"default";
};
return null;
}
}