File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about Generics in Arrays 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 "Question about Generics in Arrays" Watch "Question about Generics in Arrays" New topic
Author

Question about Generics in Arrays

Frank Hinkel
Greenhorn

Joined: Mar 28, 2008
Posts: 24
Hi folks,
i dont get where the problem is with this line:

List <Integer> i[] = {new ArrayList<Integer>(), new ArrayList<Integer>()};

PS: It is not a copy of any mock test. Just a pervert idea from a colleague at work. :-)
mayur dhawan
Greenhorn

Joined: Sep 20, 2005
Posts: 29
Hi Frank,
Java generics don't permit creation of Arrays of generics.That's why you are getting error.

thanks
mayur
Frank Hinkel
Greenhorn

Joined: Mar 28, 2008
Posts: 24
But why is it so?
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 802

List <?> i[] = {new ArrayList<Integer>(), new ArrayList<Integer>()};
why above code compiles?


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Already discussed ,
see this


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 802

http://www.bloggingaboutjava.org/2006/01/java-generics-quirks/
thanks Sagar Rohankar
I gone thru your link and I found very useful info of above link at your posted link

Thanks

Regards
Ninad
Frank Hinkel
Greenhorn

Joined: Mar 28, 2008
Posts: 24
Thanks ranchers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about Generics in Arrays