-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTest.java
More file actions
55 lines (42 loc) · 898 Bytes
/
Test.java
File metadata and controls
55 lines (42 loc) · 898 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
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Test {
public static void main(String[] args) {
A a = A.mkA(23, 42);
Iterator<Integer> iter = a.getL().iterator();
removeOdd(iter);
}
private static void removeOdd(Iterator<Integer> iter) {
while (iter.hasNext()) {
if (iter.next()%2 != 0)
iter.remove();
}
}
}
class A {
private List<Integer> l;
private A(List<Integer> l) {
this.l = l;
}
public static A mkA(Integer... is) {
return new A(Arrays.asList(is));
}
public static A mkA2(int i) {
return new A(Collections.singletonList(i));
}
public List<Integer> getL() {
return l;
}
}
class Parent<T> {
public void removeFirst(List<T> l) {
l.iterator().remove();
}
}
class Child extends Parent<String> {
public void test(String... ss) {
removeFirst(Arrays.asList(ss));
}
}