user3644708
user3644708

Reputation: 2495

Java Map Generic

the top map has 3 sub maps and each sub map has different object.

like the following code, how can I add generic to the map top?

    Map<String,Map> top = new ConcurrentHashMap<String, Map>();

    Map<String,TypeA> subA = new ConcurrentHashMap<String,TypeA>();
    Map<Long,TypeB> subB = new ConcurrentHashMap<String,TypeB>();
    Map<String, long[]> sbuC = new ConcurrentHashMap<String,TypeC>();
    top.put("SUB_A", subA);
    top.put("SUB_B", subB);
    top.put("SUB_C", subC);

Upvotes: 0

Views: 621

Answers (1)

Jens
Jens

Reputation: 69495

Try this:

Map<String,Map<<? extends  Object,?>> top = new ConcurrentHashMap<String, Map< <? extends Object,?>>();

Key is an object and the value is any type.

Upvotes: 2

Related Questions