Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics & collections question

 
Thierry Henry
Greenhorn
Posts: 1
  • 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
Posts: 15627
46
Android IntelliJ IDE Java Scala Spring
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic