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 753B

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