• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Generics in Arrays

 
Frank Hinkel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,
Java generics don't permit creation of Arrays of generics.That's why you are getting error.

thanks
mayur
 
Frank Hinkel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why is it so?
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List <?> i[] = {new ArrayList<Integer>(), new ArrayList<Integer>()};
why above code compiles?
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already discussed ,
see this
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ranchers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic