I was looking inside Arrays class in java and saw that @SuppressWarnings("unchecked") annotation is being used in the following code.
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
@SuppressWarnings("unchecked")
T[] copy = ((Object)newType == (Object)Object[].class)
? (T[]) new Object[newLength]
: (T[]) Array.newInstance(newType.getComponentType(), newLength);
System.arraycopy(original, 0, copy, 0,
Math.min(original.length, newLength));
return copy;
}
How would you refactor the following code in order to remove @SuppressWarnings("unchecked") annotation?