I have a generic class Class1<K, V> which takes two types. Now I want to maintain a map which maps String to Class1 objects i.e Map<String, Class1> . Can I retrieve the types (K,V) of each Class1 Object while I iterate through Map?
i.e lets think of code as below
Map<String, Class1> map;
map.put("1", Class1<String, Integer> obj1);
map.put("2", Class1<String, Double> obj2);
map.put("3", Class1<Integer, Double> obj3);
Now when I iterate over the map ... Can I somehow get the types(K, V) of each Class1 object??
Class1correctly and createobj1is created with an explicitStringandIntegerobject or a reference to their types.Class1actually looks like - and they might no be possible in your case (possible solutions: if the types are types of fields try to get them from those, if you can use non-generic sub classes you could use reflection, or pass type references likeString.classetc. to the constructor and store those) .