Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to declare collection containing other collection classes?

843793Nov 20 2009 — edited Nov 21 2009
How can I properly declare the generic type of a static collection variable which contains Class objects for other collections?
private static final Set<Class<? extends Collection>> COLLECTION_TYPES
    = new HashSet<Class<? extends Collection>>(
        Arrays.asList(Set.class, List.class));
This compiles, but with a warning about the raw Collection type. If I change "Collection" to "Collection<?>" for both the variable type and constructor I get this error.
The constructor HashSet<Class<? extends Collection<?>>>
(List<Class<? extends Collection>>) is undefined
Edited by: Nick_Radov on Nov 20, 2009 4:47 PM

Edited by: Nick_Radov on Nov 20, 2009 4:47 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2009
Added on Nov 20 2009
2 comments
195 views