View Single Post
  #1 (permalink)  
Old 11-17-2009, 11:32 PM
stijn1989 stijn1989 is offline
Member
 
Join Date: Nov 2009
Posts: 3
Rep Power: 0
stijn1989 is on a distinguished road
Post Creating generic arrays
Hello

I followed a conference about java generics at Devoxx. The person who gave the presentation was a prof. at the university of Leuven, Belgium. He told that you can't create an array of generics. Let me give an example.

Code:
T [] names = new T[10];
The new T[10] part gives the error. That's something I don't understand. The T in this piece of code is replaced by the name of the class during the compiling. So this should change to this for example:

Code:
String [] names = new String[10];
So during runtime this creates a array holding Strings. I understand that you can't do the follow thing because you don't know the constructor of T.

Code:
T obj = new T;
Can someone explain why I can't create a generic array. Thanks!
Reply With Quote