2019-11-27 08:00:01 +00:00
|
|
|
/*
|
2020-12-30 17:20:54 +00:00
|
|
|
* @test /nodynamiccopyright/
|
2019-11-27 08:00:01 +00:00
|
|
|
* @bug 8231827
|
|
|
|
* @summary Testing pattern matching against the null constant
|
2023-05-22 04:24:06 +00:00
|
|
|
* @run main NullsInPatterns
|
2019-11-27 08:00:01 +00:00
|
|
|
*/
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class NullsInPatterns {
|
|
|
|
|
2023-05-22 04:24:06 +00:00
|
|
|
public static void main(String... args) {
|
2019-11-27 08:00:01 +00:00
|
|
|
if (null instanceof List t) {
|
|
|
|
throw new AssertionError("broken");
|
|
|
|
} else {
|
|
|
|
System.out.println("null does not match List type pattern");
|
|
|
|
}
|
|
|
|
//reifiable types not allowed in type test patterns in instanceof:
|
|
|
|
// if (null instanceof List<Integer> l) {
|
|
|
|
// throw new AssertionError("broken");
|
|
|
|
// } else {
|
|
|
|
// System.out.println("null does not match List<Integer> type pattern");
|
|
|
|
// }
|
|
|
|
if (null instanceof List<?> l) {
|
|
|
|
throw new AssertionError("broken");
|
|
|
|
} else {
|
|
|
|
System.out.println("null does not match List<?> type pattern");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|