Possible Duplicate:
What is the easiest alternative to a generic array in Java?
I have the following code:
class B<X>
{
public void create()
{
List<X> l1 = new ArrayList<X>(); //No ERROR
X[] arrr = new X[10]; //ERROR
}
}
I know that I cannot instantiate a Generic array due to type erasure. But why can I instantiate an instance of a generic List?
new ArrayList<X>();is essentially treated asnew ArrayList<Object>();due to type erasure, why isnew X[10];not handled likenew Object[10];? - or vice-versa, if Java can't handle the array, how can it handle the list?