-
Notifications
You must be signed in to change notification settings - Fork 0
/
LowerBoundWildCard9.java
52 lines (32 loc) · 1.06 KB
/
LowerBoundWildCard9.java
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
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.io.Serializable;
import java.lang.Iterable;
public class LowerBoundWildCard9 {
public static void test(List<? super Number> num, Integer a) {
num.add(a);
System.out.println("List elements: " + num);
for (Object n : num) {
System.out.println(n);
}
Iterator<? super Number> it = num.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Iterable<? super Number> it2 = num;
for (Object n : it2) {
System.out.println(n);
}
}
public static void main(String[] args) {
ArrayList<Number> list = new ArrayList<>();
ArrayList<Object> list1 = new ArrayList<>();
ArrayList<Serializable> list3 = new ArrayList<>();
test(list, 1);
test(list, 2);
test(list, 3);
test(list1, 2);
test(list3, 4);
}
}