I have a stupid stupid question, but sometimes you have to ask them anyway.
I have an instance of Object [] in my left hand (it comes from a non-generic swing) and a method that takes a say Integer [] clause as an argument (in my case it is actually vararg) in my right hand, I am sure of the contents of the array ( or am I willing to pay the price if I am wrong).
So basically I wrote this:
private static <U, T extends U> T[] cast(final U[] input, final Class<T> newType) {
final T[] result = (T[]) Array.newInstance(newType, input.length);
System.arraycopy(input, 0, result, 0, input.length);
return result;
}
Can you remove a warning without disconnecting it?
why wasn't Array.newInstance () generalized?
source
share