26 lines
745 B
Java
26 lines
745 B
Java
// arrays/ParameterizedArrayType.java
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://OnJava8.com for more book information.
|
|
|
|
class ClassParameter<T> {
|
|
public T[] f(T[] arg) { return arg; }
|
|
}
|
|
|
|
class MethodParameter {
|
|
public static <T> T[] f(T[] arg) { return arg; }
|
|
}
|
|
|
|
public class ParameterizedArrayType {
|
|
public static void main(String[] args) {
|
|
Integer[] ints = { 1, 2, 3, 4, 5 };
|
|
Double[] doubles = { 1.1, 2.2, 3.3, 4.4, 5.5 };
|
|
Integer[] ints2 =
|
|
new ClassParameter<Integer>().f(ints);
|
|
Double[] doubles2 =
|
|
new ClassParameter<Double>().f(doubles);
|
|
ints2 = MethodParameter.f(ints);
|
|
doubles2 = MethodParameter.f(doubles);
|
|
}
|
|
}
|