I've learned following two methods for creating generic arrays.
One is
@SuppressWarnings("unchecked")
static <T> T[] array1(final Class<T> elementType, final int size) {
return (T[]) Array.newInstance(elementType, size);
}
And the other is
static <T> T[] array2(final Class<T[]> arrayType, final int size) {
return arrayType.cast(Array.newInstance(arrayType.getComponentType(), size));
}
Which is better? Are they same (internally)? Is any case actually wrong?