Community
Participate
Working Groups
There appears to be a problem with declaring a variable of some generic type and initializing it to a subclass of that type, which should work fine. (Note that this may be a duplicate of bug #72754) Below is an example: Map<String, Set<String>> m = new TreeMap<String, TreeSet<String>>(); Then faced with this code, the Eclipse compiler complains: "Type mismatch: cannot convert from TreeMap<String,TreeSet<String>> to Map<String,Set<String>>". I suspect that this may be a duplicate of bug #72754 because a declaration without nested generics, such as Map<String, String>, works just fine. But since it may not be (this has to do with variable assignment, not method invocation), I felt I should bring it to your attention. Thank you.
You cannot pass in a TreeSet since it expects a Set. Read up on subtypes & generics. java version "1.5.0-rc", build 1.5.0-rc-b63 complains with: test.java:5: incompatible types found : java.util.TreeMap<java.lang.String,java.util.TreeSet<java.lang.String> > required: java.util.Map<java.lang.String,java.util.Set<java.lang.String>> Map<String, Set<String>> m = new TreeMap<String, TreeSet<String> >(); ^ 1 error
A workaround for the original poster would be to declare Map<String, ? extends Set<String>> m