Add basic support for case guards

This commit is contained in:
Chris Smowton
2023-10-27 17:31:47 +01:00
parent e94c5a772c
commit ba0f3cf718
3 changed files with 66 additions and 28 deletions

View File

@@ -82,6 +82,12 @@ class A {
case null -> "Null";
default -> "Not null";
};
var whenTest = switch((String)thing) {
case "constant" -> "It's constant";
case String s when s.length() == 3 -> "It's 3 letters long";
case String s when s.length() == 5 -> "it's 5 letters long";
default -> "It's something else";
};
}
}
catch (RuntimeException rte) {