diff options
Diffstat (limited to 'tests/features199/java18/SwitchPatternPreview2Aspect.aj')
-rw-r--r-- | tests/features199/java18/SwitchPatternPreview2Aspect.aj | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/features199/java18/SwitchPatternPreview2Aspect.aj b/tests/features199/java18/SwitchPatternPreview2Aspect.aj new file mode 100644 index 000000000..ee5dbbd68 --- /dev/null +++ b/tests/features199/java18/SwitchPatternPreview2Aspect.aj @@ -0,0 +1,28 @@ +import java.util.Locale; + +aspect SwitchPatternPreview2Aspect { + Object around(Object o): execution(* doSomethingWithObject(*)) && args(o) { + System.out.println( + switch (o) { + case -1, 1 -> "special case:" + o; + case Integer i && i > 0 -> "positive integer: " + o; + case Integer i -> "other integer: " + o; + default -> "non-integer: " + o; + } + ); + return proceed(o); + } +} + +class Application { + public static void main(String[] args) { + doSomethingWithObject(-1); + doSomethingWithObject(0); + doSomethingWithObject(42); + doSomethingWithObject(-99); + doSomethingWithObject("test"); + doSomethingWithObject(null); + } + + public static Object doSomethingWithObject(Object o) { return o; } +} |