I didnt even know that method existed (Java 6 only).
http://java.sun.com/javase/6/docs/api/java/util/Arrays.html
Why is this method (and its 10 variants - 20 if you count CopyOf) even necessary?
It does exactly the same thing as System.arraycopy
except that it creates a new array instead of being passed one.
At most that saves you one line of code (a new array initialization).
int[] source...;
int[] target...;
System.arraycopy(source, 0, target, 0, source.length);
vs
int[] source...;
int[] target = Arrays.copyOfRange(source, 0, source.length)
Isnt this just bloating the API for no good reason at all?
I mean all theyve done is make 10 copies of a method that already exists.
As for the original question: if your class object is already a subclass of T[] then you don't have to do anything. But if it is not, then there is nothing you can do to cause it to be one.
Maybe you could ask your earlier question, the one which is the background to this one. Because this one doesn't really make any sense to me.
TuringPest:
I meant using the following method:
static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)
This method is great. It instantiates a new array, copies elements to it, and controls the destination array type. No existing method provide all this.
DrClap:
I simply need to create an array of type T (known at runtime). So the class passed could be String[].class, Integer[].class, Object[].class, ... etc. I tested it with hardcoding the type and it worked.
I think the problem is with the syntax rather than the relationship between the class object and T[] because I am getting a compilation error not a runtime error.