Reputation: 821
How to declare such a Map where instead of Object I have specific type:
Map<Class, Map<String, ClassInstance>> map;
Such that could be used as:
Map<String, new Type()) valueMap = new HashMap();
map.put(Type.class, valueMap);
The problem is I can't figure out how to declare generic type of both 'Class' and 'ClassInstance'.
Upvotes: 0
Views: 89
Reputation: 159215
Map<Class<?>, Map<String, Object>> map;
You cannot statically enforce that the Object
is of the given type. That's for your code to enforce.
Map<String, Object> valueMap = new HashMap<>();
valueMap.put("Foo", new Type());
map.put(Type.class, valueMap);
Upvotes: 1