aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features199/java18/SwitchPatternPreview2Error.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/features199/java18/SwitchPatternPreview2Error.java')
-rw-r--r--tests/features199/java18/SwitchPatternPreview2Error.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/features199/java18/SwitchPatternPreview2Error.java b/tests/features199/java18/SwitchPatternPreview2Error.java
new file mode 100644
index 000000000..b1652aad3
--- /dev/null
+++ b/tests/features199/java18/SwitchPatternPreview2Error.java
@@ -0,0 +1,31 @@
+/**
+ * Inspired by examples in https://openjdk.java.net/jeps/420
+ */
+public class SwitchPatternPreview2Error {
+ static void constantLabelMustAppearBeforePattern1(Object o) {
+ switch (o) {
+ case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+ case -1, 1 -> System.out.println("special case:" + o);
+ case Integer i -> System.out.println("other integer: " + o);
+ default -> System.out.println("non-integer: " + o);
+ }
+ }
+
+ static void constantLabelMustAppearBeforePattern2(Object o) {
+ switch (o) {
+ case -1, 1 -> System.out.println("special case:" + o);
+ case Integer i -> System.out.println("other integer: " + o);
+ case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+ default -> System.out.println("non-integer: " + o);
+ }
+ }
+
+ static void constantLabelMustAppearBeforePattern3(Object o) {
+ switch (o) {
+ case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+ case Integer i -> System.out.println("other integer: " + o);
+ case -1, 1 -> System.out.println("special case:" + o);
+ default -> System.out.println("non-integer: " + o);
+ }
+ }
+}