Community
Participate
Working Groups
The following code compiles with javac, but not with eclipse: Properties properties = new Properties(); for ( Map.Entry<String, ?> entry : ( (Map<String, ?>) props ).entrySet() ) { System.out.println(entry); } A Properties implements Map<K,V> so the above should work IMO.
It compiles with javac 1.5.0_07, but not with javac 1.5.0_08. X.java:8: inconvertible types found : java.util.Properties required: java.util.Map<java.lang.String,?> for (Map.Entry<String, ?> entry : ((Map<String, ?>) props).entrySet()) { ^ 1 error import java.util.Map; import java.util.Properties; public class X { public static void main(String[] args) { Properties props = new Properties(); for (Map.Entry<String, ?> entry : ((Map<String, ?>) props).entrySet()) { System.out.println(entry); } } } Also fail with javac 6.0b88. This looks like a fixed bug.
ah, those pesky nano updates. sorry for bothering you ;)
...just as sidenote: What rule is broken here ? (if you know)
Properties is not a subtype of Map<String,?>. It inherits from Map<Object,Object>, which is provably distinct from Map<String,?>. The following would work: import java.util.Map; import java.util.Properties; public class X { public static void main(String[] args) { Properties props = new Properties(); for (Map.Entry<Object, ?> entry : ((Map<Object, ?>) props).entrySet()) { System.out.println(entry); } } } or you could even use: Map.Entry<?, ?> entry : ((Map<?, ?>). BTW, I don't get what the cast buys you here.
It works as per design. Added GenericTypeTest#test1023
i understand. the only thing it bought were no need to cast the key to a string.