-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathUnionTypes.java
More file actions
58 lines (48 loc) · 1.17 KB
/
UnionTypes.java
File metadata and controls
58 lines (48 loc) · 1.17 KB
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
58
import java.util.*;
import java.util.concurrent.*;
public class UnionTypes {
public void m1() {
m1_map_put(new LinkedHashMap<>(), "k", "v");
m1_map_put(new ConcurrentHashMap<>(), "k", "v");
}
private void m1_map_put(Map<String, String> m, String k, String v) {
m.put(k, v);
}
static class Sup { }
interface Inter { }
static class A1 extends Sup implements Inter { }
static class A2 extends Sup implements Inter { }
static class A3 extends Sup { }
static class A4 extends Sup implements Inter { }
static class A2sub extends A2 { }
private void m2(boolean b) {
scc1(new A1(), 10);
Sup x = b ? new A2() : new A3();
scc2(x, 10);
}
private void scc1(Sup x1, int i) {
scc2(x1, i);
}
private void scc2(Sup x2, int i) {
scc3(x2, i);
}
private void scc3(Sup x3, int i) {
next(x3);
if (i > 0)
scc1(x3, --i);
}
private void next(Sup x) {
if (x instanceof Inter) {
x.hashCode();
}
var hashCode = switch (x) {
case Inter i -> x.hashCode();
default -> 0;
};
}
void m3(Object d) {
if (d instanceof A1 || d instanceof A2 || d instanceof A3) {
d.hashCode();
}
}
}