• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics & collections question

 
Thierry Henry
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i'm trying to create a type L that extends a List containing elements of type E.



I can't create an instance in the above example.. Anyone has some pointers or an example of how to go about this?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm not mistaken, this is unfortunately not possible, because of the way Java generics currently work (with type erasure).

See this from Angelika Langer's excellent Java Generics FAQ:
Can I create an object whose type is a type parameter?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic