Friday, February 25, 2005

Sun Generics tutorial bug



As per the Sun Generics tutorial page # 15, Section 7.3 - Arrays, you can declare array types whose element type is a type variable or a parameterized type, but not array objects.

The sample code there states that the following is legal but would generate unchecked warning.


List<String> c[] = new List<?>[10];


But actually this code doesn't compile and so it doesn't appear to be legal. It seems only unbounded wild cards are allowed for both array types and array objects. So following code is legal and it works too:


List<?> c[] = new List<?>[10];


Very strange this being the "official" tutorial. Hope someone fixes this soon.

No comments: