You want a Map<Class<?>, Class<?>>
.
Class
here refers to java.lang.Class
, which is a generified type. Unless you have more specific bounds, the unbounded wildcard <?>
can be used (see Effective Java 2nd Edition, Item 23: Don't use raw types in new code)
Note that the interface Map
is used here instead of a specific implementation HashMap
(see Effective Java 2nd Edition, Item 52: Refer to objects by their interfaces).
Note that Map<Class<?>, Class<?>>
still maps objects, but the type of those objects are now Class<?>
. They are still objects nonetheless.
See also
Related questions
Imposing restrictions with bounded wilcards
Here's an example of imposing bounded wildcards to have a Map
whose keys must be Class<? extends Number>
, and values can be any Class<?>
.
Map<Class<? extends Number>, Class<?>> map
= new HashMap<Class<? extends Number>, Class<?>>();
map.put(Integer.class, String.class); // OK!
map.put(Long.class, StringBuilder.class); // OK!
map.put(String.class, Boolean.class); // NOT OK!
// Compilation error:
// The method put(Class<? extends Number>, Class<?>)
// in the type Map<Class<? extends Number>,Class<?>>
// is not applicable for the arguments (Class<String>, Class<Boolean>)
As you can see, the generic compile-time typesafety mechanism will prevent String.class
from being used as a key, since String
does not extends Number
.
See also