You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SwitchPatternPreview2Aspect.aj 765B

1234567891011121314151617181920212223242526
  1. aspect SwitchPatternPreview2Aspect {
  2. Object around(Integer i): execution(* doSomethingWithInteger(*)) && args(i) {
  3. System.out.println(
  4. switch (i) {
  5. case null -> "value unavailable: " + i;
  6. case -1, 1 -> "absolute value 1: " + i;
  7. case Integer value && value > 0 -> "positive integer: " + i;
  8. default -> "other integer: " + i;
  9. }
  10. );
  11. return proceed(i);
  12. }
  13. }
  14. class Application {
  15. public static void main(String[] args) {
  16. doSomethingWithInteger(-1);
  17. doSomethingWithInteger(0);
  18. doSomethingWithInteger(42);
  19. doSomethingWithInteger(-99);
  20. doSomethingWithInteger(Integer.valueOf(123));
  21. doSomethingWithInteger(null);
  22. }
  23. public static Object doSomethingWithInteger(Integer o) { return o; }
  24. }