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!

Maps, Lists, Iterators and captures

843793May 19 2005 — edited Mar 13 2006
I have little troubles expressing my intentions using Java Generics.

I want to iterate over a map where each entry's value is a list of some type, that is
Map<?, ? extends List<?>> map 
What would the type of a iterator over the entry-set of this map look like?

My first guess was
Iterator<Map.Entry<?, ? extends List<?>>> it=map.entrySet().iterator()
but the compiler tells me
/tmp/16462/Test.java:9: incompatible types
found   : java.util.Iterator<java.util.Map.Entry><capture of ?,capture of ? extends java.util.List><?>>>
required: java.util.Iterator<java.util.Map.Entry><?,java.util.List<?>>>
    Iterator<Map.Entry><?,List<?>>> it = map.entrySet().iterator();
What does the compiler mean with 'capture of ?' ?

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 10 2006
Added on May 19 2005
11 comments
378 views