-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpperBoundWildCardMeth1.java
59 lines (37 loc) · 1.02 KB
/
UpperBoundWildCardMeth1.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
package com.company;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.lang.Iterable;
public class UpperBoundWildCardMeth1{
public static <T extends List<? extends Number>> T test (T t)
{
System.out.println("List elements: " + t);
for (Number n : t) {
System.out.println(n);
}
Iterator<? extends Number> it = t.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Iterable<? extends Number> it2 = t;
for (Number n : it2) {
System.out.println(n);
}
return t;
}
public static void main(String[]args) {
List<Integer> intList = new ArrayList<>();
intList.add(1);
intList.add(2);
intList.add(3);
intList.add(4);
intList.add(5);
intList.add(6);
intList.add(7);
intList.add(10);
intList.add(11);
intList.add(12);
System.out.println(test(intList));
}
}