Problem is that while runtime generic type is erased so new E[10]
would be equivalent to new Object[10]
.
This would be dangerous because it would be possible to put in array other data than of E
type. That is why you need to explicitly say that type you want by either
- creating Object array and cast it to
E[]
array, or
- useing Array.newInstance(Class componentType, int length) to create real instance of array of type passed in
componentType
argiment.