-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLowerBoundWildCard8.java
65 lines (49 loc) · 1.8 KB
/
LowerBoundWildCard8.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
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class LowerBoundWildCard8 {
public static <T extends Map<? super String, ? super Number>> T test(T t, Integer a, String b) {
t.put(b, a);
System.out.println("List elements: " + t);
for (Object n : t.keySet()) {
System.out.println("keys = " + n);
}
for (Object n : t.values()) {
System.out.println("Values = " + n);
}
Iterator<? super String> it = t.keySet().iterator();
while (it.hasNext()) {
System.out.println("Keys =" + it.next());
}
Iterator<? super Number> it1 = t.values().iterator();
while (it1.hasNext()) {
System.out.println("Values =" + it1.next());
}
Iterable<? super String> it2 = t.keySet();
for (Object num : it2) {
System.out.println("Values =" + num);
}
Iterable<? super Number> it3 = t.values();
for (Object num : it3) {
System.out.println("Values =" + num);
}
return t;
}
public static void main(String[] args) {
HashMap<String, Number> map = new HashMap<>();
HashMap<String, Serializable> map1 = new HashMap<>();
HashMap<String, Object> map2 = new HashMap<>();
HashMap<Object, Number> map3 = new HashMap<>();
HashMap<Object, Serializable> map4 = new HashMap<>();
HashMap<Object, Object> map5 = new HashMap<>();
test(map, 1, "a");
test(map, 2, "b");
test(map, 3, "c");
test(map1, 2, "d");
test(map2, 3, "e");
test(map3, 4, "f");
test(map4, 5, "g");
test(map5, 6, "h");
}
}