Community
Participate
Working Groups
Build ID: I20070323-1616 Steps To Reproduce: 1. See code in the "More information" section. In the example, the line "Map.Entry<String, String> entry : myMap().entrySet()" gives the following error: "Type mismatch: cannot convert from element type Object to Map.Entry<String,String>". I could be wrong but this smells like a bug (the cream-filled, crunchy kind). The generic nature of "myMap" has nothing to do with the generic nature of the enclosing class nor of the inner class. The error is fixed if you change the extends clause of the inner class to include the generic markup (eg. "extends GenericsBugInEclipse<T>" instead of "extends GenericsBugInEclipse"). This happens in a 3.2 build as well. More information: import java.util.HashMap; import java.util.Map; public class GenericsBugInEclipse<T> { private final Map<String, String> myMap; private final T theGenericThing; private GenericsBugInEclipse(T something) { this.myMap = new HashMap<String, String>(); this.theGenericThing = something; } public static class InnerClassThatShowsBug extends GenericsBugInEclipse { public InnerClassThatShowsBug() { super(null); } public void printMap() { for (Map.Entry<String, String> entry : myMap().entrySet()) { System.out.println(entry.getKey() + " => " + entry.getValue()); } } } protected Map<String, String> myMap() { return myMap; } }
Unfortunately, this is working as designed. Javac 1.5 and 1.6 both report the same error as we do. This is a consequence of using a raw supertype. The raw conversion is applied to all non-static member signatures, even if they weren't referring to the type parameter T itself. In your case, the #getMap() method from raw supertype as Map (raw) as its return type, instead of Map<String,String>. i.e. blame the spec.
Added GenericTypeTest#test1124
OK, thanks for investigating though and for the explanation.
OK, thanks for investigating and offering up the explanation. I thus blame the spec!
Verified for 3.3M7