-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathA.java
More file actions
129 lines (113 loc) · 2.47 KB
/
A.java
File metadata and controls
129 lines (113 loc) · 2.47 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.util.*;
public class A extends ArrayList<Long> {
Object f1 = null;
Object f2 = new ArrayList<Long>();
public void m1(List<Long> l, List<Integer> l2) {
f1 = new ArrayList<Long>();
f2 = f1;
f2 = l;
Object x = m2(f2, l.size());
Object z = x;
Object y = l.isEmpty() ? this : (Object)null;
z = y;
if (l.size() > 3)
y = (Object)new ArrayList<Integer>();
else
y = l2;
z = y;
}
private Object m2(Object o, int i) {
if (i == 7)
return null;
else if (i == 8)
return o;
else
return new ArrayList<Long>();
}
public void m3(Set<Integer> s) {
Object r;
for (Object x : s) {
r = x;
}
for (Object x : new A[3]) {
r = x;
}
}
public Object m4(Object o) {
if (o instanceof Long) {
return o;
}
return o;
}
public Object m5(Object o) {
try {
Integer i = (Integer)o;
Object o2 = o;
} catch(ClassCastException cce) {
return o;
}
return o;
}
public void m6(int[] xs) {
Object r;
for (Object x : xs) {
r = x;
}
}
public void m7() {
Object x = 7;
int i = (Integer)x;
int j = i;
Object x2 = (Integer)7;
int i2 = (Integer)x2;
int j2 = i2;
}
public static class C {
private Map<String, String> map;
public static C empty = new C(Collections.emptyMap());
private C(Map<String, String> map) {
this.map = map;
}
public C() {
this(new LinkedHashMap<>());
}
public void put(String k, String v) {
map.put(k, v);
empty.put(k, v);
}
}
public void m8(Object[] xs, int i) {
if (xs[i] instanceof Integer) {
Object n = xs[i];
Object r = n;
}
}
public void m9(Object[] xs, int i) {
switch (xs[i]) {
case Integer i2 -> {
Object n = xs[i];
Object r = n;
}
default -> { }
}
}
public void m10(Object o) {
String s = "Hello world!";
Object o2 = s; // Alas, the type information, it is lost
if (o2 instanceof CharSequence cs) {
// Partially recovered statically, but we should know cs is an alias of o and therefore it's really a string.
Object target = cs;
}
// The same applies to a pattern case
switch (o2) {
case CharSequence cs -> { Object target = cs; }
default -> { }
}
}
private static <T> T lookupFoo(Map<String, T> m) {
return m.get("foo");
}
public void m11(Map<String, String> m) {
lookupFoo(m);
}
}