Actually, the question should be
Creating an array of generic anything.
Why can\'t the compiler take care of it?
The following would be
I do know that, relative to the workarounds to this issue, Array.newInstance() is an expensive method to call. IIRC it uses a native method to instantiate the array, amidst the other reflection involved. I can't offer any statistics, but this seems like a good enough reason for such functionality not to be automatically substituted in by the compiler in order to allow generic array creation. Especially given the existence of ArrayList
, etc. it just doesn't seem like a pressing issue.