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!

Map iterator

831231Jan 14 2011 — edited Jan 17 2011
Dear forum,

I have some trouble with Java generics I cannot figure out myself.
What I have is a method that takes a Map<String, ? extends Object> as parameter.

Why can't I create an iterator for that map like that:
public static String[] getStrings(final Map<String, ? extends Object> p_tmInput)
{
    Iterator<Map.Entry<String, Object>> it = p_tmInput.entrySet().iterator();
    ...
}
Doing so my compiler says:

Type mismatch: cannot convert from Iterator<Map.Entry<String,capture#3-of ? extends Object>> to Iterator<Map.Entry<String,Object>>

My understanding of bounded wildcards in Java at the moment says that that map contains java.lang.String as keys and any objects deriveing from java.lang.Object.
I would be glad for any hint.


Thanks in advance and best regards,

Sebastian
This post has been answered by 802316 on Jan 17 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 14 2011
Added on Jan 14 2011
6 comments
4,165 views