diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2022-08-26 00:53:21 +0200 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2023-01-12 00:37:54 +0100 |
commit | 7928cf4ba05e3b9e858be655dc43e60f0335dacd (patch) | |
tree | 4da7bede5d0c06890252505eb4053aa9cc7a897d /test/pretty/resource/before/Switch19.java | |
parent | fedc92663e563079c3b6a09c58ab3f73372000fe (diff) | |
download | lombok-7928cf4ba05e3b9e858be655dc43e60f0335dacd.tar.gz lombok-7928cf4ba05e3b9e858be655dc43e60f0335dacd.tar.bz2 lombok-7928cf4ba05e3b9e858be655dc43e60f0335dacd.zip |
[jdk19] Add support for new guard pattern
Diffstat (limited to 'test/pretty/resource/before/Switch19.java')
-rw-r--r-- | test/pretty/resource/before/Switch19.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/pretty/resource/before/Switch19.java b/test/pretty/resource/before/Switch19.java new file mode 100644 index 00000000..05b27928 --- /dev/null +++ b/test/pretty/resource/before/Switch19.java @@ -0,0 +1,33 @@ +// version 19: +public class Switch19 { + String switchPatternMatching(Object o) { + return switch (o) { + case Integer i -> String.format("int %d", i); + case Long l -> String.format("long %d", l); + case Double d -> String.format("double %f", d); + case String s -> String.format("String %s", s); + default -> o.toString(); + }; + } + + String switchNull(Object o) { + return switch (o) { + case null, default -> "?"; + }; + } + + String switchGuardPattern(Object o) { + return switch (o) { + case String s when s.length() > 1 -> s; + case String s -> s; + default -> o.toString(); + }; + } + + String switchParenthesizedPattern(Object o) { + return switch (o) { + case (String s) -> s; + default -> o.toString(); + }; + } +} |