-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGenericsVarargs.java
More file actions
36 lines (29 loc) · 943 Bytes
/
GenericsVarargs.java
File metadata and controls
36 lines (29 loc) · 943 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
package generics;
import java.util.*;
/**
* RUN:
* javac generics/GenericsVarargs.java && java generics.GenericsVarargs
* OUTPUT:
* Note: generics\GenericsVarargs.java uses unchecked or unsafe operations.
* Note: Recompile with -Xlint:unchecked for details.
* [A]
* [A, B, C]
* [, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
*/
public class GenericsVarargs {
public static <T> List<T> makeList(T... args) {
List<T> result = new ArrayList<T>();
for (T item : args) {
result.add(item);
}
return result;
}
public static void main(String[] args) {
List<String> ls = makeList("A");
System.out.println(ls);
ls = makeList("A", "B", "C");
System.out.println(ls);
ls = makeList("ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""));
System.out.println(ls);
}
}