I mean, is there any good reason for that? The method's got the following signature:
public static Object newInstance(Class<?> componentType,
int length)
throws NegativeArraySizeException
In my opinion, it would be much more convinient to declare the method as follows:
public static <T> T[] newInstance(Class<T> componentType, int length)
throws NegativeArraySizeException
That way, when creating an aray of generic type it would not be neccesary to perform additional casting, e.g.
public class Gen<T>{
private T[] a;
public static <T> Gen<T> createByClass(Class<T> clazz){
a = clazz.cast(Array.newIntance(clazz.getComponentType(), 8); //we have to invoke
//clazz.cast here.
}
}
Was there any good reason to declare the return value type as Object? To me it seems very incovinient.
int.classetc.int.class? I thought that requesting class objects of primitives always returns their reference wrapper class object...Array.newInstance(int.class, 5)you'll get anint[]back, not anInteger[].