import java.util.Arrays;
public class MyClass
{
public static <T, U> U[] CopyArray(T[] arr, Class<U[]> newType) {
return Arrays.copyOf(arr, arr.length, newType);
}
public static void main(String[] args)
{
Number[] arr = { 1, 2, 3, 4, 5, 6, 7 };
try {
Integer[] dest = CopyArray(arr, Integer[].class);
System.out.println(Arrays.toString(dest));
} catch (ArrayStoreException ex) {
System.out.println("Exception: " + ex);
}
}
}
/*
run:
[1, 2, 3, 4, 5, 6, 7]
*/