Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Generics & collections question
Thierry Henry
Greenhorn
Posts: 1
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
i'm trying to create a type L that extends a List containing elements of type E.
public class ListTest<L extends List<E>, E> { public void test() { // I want to be able to do smth like this L<Integer> list = new ArrayList<Integer>(); L<String> vector = new Vector<String>(); } }
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
Posts: 16084
88
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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?
Jesper's Blog
-
Pluralsight Author Page
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Generic return type
Generics
LinkedList problem
Generic return types
Help Me Downcast
More...