mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 18:15:55 +00:00
[jdk19] Add support for new guard pattern
This commit is contained in:
1 parent
646723f6d3
commit
957adfae2e
4 files changed
+77
-1
No files matched your search
@@ -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();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user