Map in which values are concretions of a generic class Let's say I have a pool of adapter classes. All of them are concretions of a generic interface, such as:

interface Adapter&lt;Target,Source&gt; {
    Target adapt(Source object);
}


Now, my idea was to implement such a pool as a map in which keys are target and source classes:

final DoubleKeyMap&lt;Class&lt;?&gt;, Class&lt;?&gt;, Adapter&lt;Class&lt;?&gt;,Class&lt;?&gt;&gt;&gt; adapters;


And clients can ask the pool for the appropriate adapter in this manner:

(Adapter&lt;Target, Source&gt;) adapters.get(targetClass, sourceClass);


However, I'm not sure this is the 'best' way of accomplishing it.
Your clients do not need about how you are providing the Adapter&lt;>. They just have to provider the Target and Source class instances.

Here is one possible implementation,

public class DoubleKeyMap {

    private Map&lt;Wrapper, Adapter&lt;Target,Source&gt;&gt; adapterMap;

    public DoubleKeyMap(Map&lt;Wrapper, Adapter&lt;Target,Source&gt;&gt; adapterMap) {
        this.adapterMap = adapterMap;
    }

    public Adapter&lt;Target,Source&gt; get(Class&lt;Target&gt; targetClass, Class&lt;Source&gt; sourceClass) {

        Wrapper wrapper = new Wrapper(targetClass, sourceClass);

        return adapterMap.get(wrapper);
    }

    private class Wrapper {

        private Class&lt;Target&gt; target;

        private Class&lt;Source&gt; source;

        private Wrapper(Class&lt;Target&gt; target, Class&lt;Source&gt; source) {
            this.target = target;
            this.source = source;
        }
    }
}


Hide the wrapper from outside world by making it private.

The client just provide Target and Source Class instances

class Client {
    public static void main(String[] args) throws ClassNotFoundException {
        DoubleKeyMap doubleKeyMap = new DoubleKeyMap(Collections.emptyMap());

        Adapter&lt;Target, Source&gt; targetSourceAdapter = doubleKeyMap.get(Target.class, Source.class);
    }
}