Community
Participate
Working Groups
The following java class can be compiled by Sun's javac 1.5.0_04, yet Eclipse reports an error saying: Cannot cast from Properties to Map<String,String> import java.util.Map; public class Test { public static void main(String[] args) { Map<String,String> m=(Map<String, String>)System.getProperties(); } }
Given Properties extends Hashtable<Object,Object>, the cast comes down to converting Map<Object,Object> to Map<String,String> which is forbidden by the spec since these are provably distinct types.
Note that javac correctly rejects: import java.util.*; public class X { public void foo(Hashtable<Object,Object> moo) { Map<String, String> m = (Map<String, String>) moo; } } but misses the indirect case when using Properties. Closing as javac bug.