wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem on generics from nikos blog:error generic array creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem on generics from nikos blog:error generic array creation" Watch "problem on generics from nikos blog:error generic array creation" New topic
Author

problem on generics from nikos blog:error generic array creation

Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432


why we can't able to create array at line 3?
if we modify this above code and put

or[/b],
then it is ok ,code compiles fine.

Again similar problem
why the error comes here?
here if line 3 changes to
,it works fine.

SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
We can't instatiate an array of objects of parametrized type.
Refer to this link for explanation (Java Generics FAQ written by Angelika Langer
- look for an answer to question "Can I create an array whose component type is a type parameter?"):
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#Can%20I%20create%20an%20array%20whose%20component%20type%20is%20a%20type%20parameter?
Simone Aiello
Greenhorn

Joined: Oct 13, 2010
Posts: 22
Arjun Srivastava wrote:
why the error comes here?
here if line 3 changes to
,it works fine.



This code doesn't compile because the String type is shadowed by the otherone into the <> brackets.


The important is not what you know, but when you know it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem on generics from nikos blog:error generic array creation