I have declared a Map which contains mapping of keys of type Long to a Nested Map
Nested Maps has keys of Type Class and values of Type SomeClient Basically I am trying to generate a mapping of Class type to the clients which produce the response of the Class Type.
private static final Map<Long, Map<Class<? super GenericResponse>, SomeClient<? super GenericResponse>>> someClientMap
= new HashMap<Long, Map<Class<? super GenericResponse>, SomeClient<? super GenericResponse>>>(); // <? super GenericResponse> should enable me to put subclasses of type GenericResponse in the Map
The getSomeClient method is a generic method which accepts the class Type as argument and returns the client which produces responses of the Class Type.(The class type can only be a subclass of GenericResponse: notice Type parameter in the method signature)
public static <T extends GenericResponse> SomeClient<T> getSomeClient(long clientId,Class<T> clazz) throws IOException {
if (someClientMap.get(clientId) == null) {
synchronized (someClientMap) {
someClientMap.put(clientId, new HashMap<Class<T>,SomeClient<T>>()); //getting error here
}
}
return someClientMap.get(clientId);
}
The problem is that I am getting an compile time error where I am trying to put the client in the map.
The exact Error is
The method put(Long, Map<Class<? super GenericResponse>,SomeClient<? super GenericResponse>>) in the type Map<Long,Map<Class<? super GenericResponse>,SomeClient<? super GenericResponse>>> is not applicable for the arguments (long, HashMap<Class<T>,SomeClient<T>>)
I am having difficulty pointing out what exactly am I doing wrong. Please help.
Declaration for SomeClient is
public class SomeClient<T extends GenericResponse>
and for the contructor is
public SomeClient(Class<T> clazz)