Map<Object, X> is not compatible with Map<User, X>
You may want to change the declaration of your Map:
This way, you can assign any map for which the value type is List<String>. You can't put anything in this Map though, because the compiler doesn't know the actual type and therefore cannot make sure the generic constraints are enforced.
Originally posted by Tom Johnson: I think the is better as you then know what the map contains straight away
But other Maps that have other object types of keys may also be needed (I don't know, but it doesn't seem unreasonable).
Originally posted by nimo frey: hmm...now I have the question:
What is better?
or the putAll-Method ??
Using ? for the key type will remove the requirement of an extra HashMap object, but you can't add anything afterwards. Using putAll allows you to add anything, but you will need an extra object.
Now if you don't need to add anything anymore, then I'd go for ?. You can still retrieve the keys as Objects, and it saves the one object (plus the time it takes for putAll to complete). Otherwise you won't have any choice, and you need putAll.