blob: ee5dbbd6835a92e8939baf7fcfbc62b0f5e093a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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; }
}
|