2018-08-29 07:36:17 +00:00
|
|
|
/*
|
|
|
|
* @test /nodynamiccopyright/
|
|
|
|
* @bug 8206986
|
|
|
|
* @summary Check types inferred for switch expressions.
|
2019-02-21 18:29:16 +00:00
|
|
|
* @compile/fail/ref=ExpressionSwitchInfer.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ExpressionSwitchInfer.java
|
2018-08-29 07:36:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
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 "" -> {
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 0;
|
2018-08-29 07:36:17 +00:00
|
|
|
} default ->"default";
|
|
|
|
};
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|