File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Generics Question:  Map and Map.Entry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generics Question:  Map and Map.Entry" Watch "Generics Question:  Map and Map.Entry" New topic

Generics Question: Map and Map.Entry

Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

I am using the Map class and calling the entrySet() method. Its defined

I tried to call it like so

I am using Java 1.5.0_22 and Eclipse 3.2.2. It won't let me type this. It insists on having

Set<? extends Map.Entry<? extends IProperty,? extends String>> properties = propHolder.getProperties().entrySet();

This does not make sense to me. Is this a compiler or Eclipse error? I haven't manually compiled Java in so long, I figured it be faster for me to ask than to try and manually invoke the java compiler. I know Eclipse uses its own internal compiler for identifying errors and debugging sessions. I can't figure out why this should not be allowed.
Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Lets suppose we have two classes: Then our Map could contain Map.Entry<C1, String> and Map.Entry<C2, String>. My guess is that this is not the same Map.Entries, that's why you need to put Set<? extends Map.Entry>.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

I don't think so. Map.Entry<C1,String> is not the same as Map.Entry<C2,String>. Besides, the Map.Entry is defined in the Map method, so there is no choice between the two.
subject: Generics Question: Map and Map.Entry
It's not a secret anymore!