generic array creation error - ArrayList

Hi

I have a problem with "generic array creation"

1) If having an array ofArrayList<String>

ArrayList<String>[]anArray=new ArrayList<String> [ 5 ];

When compiling : ERROR as below

C:\Temp>javactest.java

test.java:8: generic array creation

ArrayList<String>[]anArray =new ArrayList<String>[ 5 ];

^

1 error

2) However, if having an array of ArrayList,(not ArrayList<String>)

ArrayList []anArray=new ArrayList [ 5 ];

When compiling : NO ERROR

C:\Temp>java -version

java version "1.5.0_07"

It is very strange. Case 1, the type of ArrayList<String> is defined without any ambiguity, then it is an ERROR in compiling

while in case 2, the ArrayList is ambiguous in what type of object it will hold, but NO ERROR in compiling

Thanks very much for your comments/advice

[1018 byte] By [mScreenNamea] at [2007-10-3 3:13:47]
# 1

http://onesearch.sun.com/search/onesearch/index.jsp?qt=generic+array+creation&qp_name=null&subCat=siteforumid%3Ajava316&site=dev&dftab=siteforumid%3Ajava316&chooseCat=javaall&col=developer-forums

The search function is your friend. The contents of the above link will tell you that you can't create generic arrays because the exact type of the array is not known at runtime. Try putting the ArrayList<String> in another List.

tvynra at 2007-7-14 21:04:50 > top of Java-index,Core,Core APIs...