-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLowerBoundWildCard6.java
51 lines (42 loc) · 1.36 KB
/
LowerBoundWildCard6.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
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.io.Serializable;
import java.lang.Iterable;
public class LowerBoundWildCard6 {
public static <T extends List<? super String>> T test (T t, String a) {
t.add(a);
if (t.contains("a") == true) {
t.remove(0);
System.out.println("value of index: 0 is removed");
}
System.out.println("List elements: " + t);
for (Object n : t) {
System.out.println(n);
}
Iterator<? super String> it = t.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Iterable<? super String> it2 = t;
for (Object n : it2) {
System.out.println(n);
}
return t;
}
public static void main(String[] args) {
List<String> list = new ArrayList<>();
List<Object> list1 = new ArrayList<>();
List<Serializable> list2 = new ArrayList<>();
List<Comparable<String>> list3 = new ArrayList<>();
List<CharSequence> list4 = new ArrayList<>();
test(list, "a");
test(list, "b");
test(list, "c");
test(list, "d");
test(list1, "d");
test(list2, "e");
test(list3, "f");
test(list4, "g");
}
}