I do not think that's possible:
Class<T> only takes T.class as a value. Class<Object> does not accept String.class , although Object is a superclass of String.
For this reason, any card with Class<T> as a key can have only one element with T.class as the key value, regardless of the value of T
The compiler will only ever accept a card with a specific parameter value T as a parameter. You cannot write Map<Class<?>, MyInterface<?>> because everyone? it is assumed to be different: it does not match Map<Class<T>, MyInterface<T>> , which requires that the value of T have the same value.
However, myMethod will only accept one-time cards that do not seem useful.
user1331740
source share