-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTest.java
More file actions
57 lines (45 loc) · 991 Bytes
/
Test.java
File metadata and controls
57 lines (45 loc) · 991 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public class Test {
record S(int x) { }
record R(S s, String y) { }
public static void test(Object o) {
switch(o) {
case String s:
break;
case R(S(int x), String y):
break;
default:
break;
}
switch(o) {
case String s -> { }
case R(S(int x), String y) -> { }
case null, default -> { }
}
var a = switch(o) {
case String s:
yield 1;
case R(S(int x), String y):
yield x;
case null, default:
yield 2;
};
var b = switch(o) {
case String s -> 1;
case R(S(int x), String y) -> x;
default -> 2;
};
if (o instanceof String s) { }
if (o instanceof R(S(int x), String y)) { }
switch(o) {
case R(S(var x), var y) -> { }
case null, default -> { }
}
if (o instanceof R(S(var x), var y)) { }
switch(o) {
case String _, Integer _:
case R(S(_), _):
default:
break;
}
}
}