I\'m not sure what I want to do is possible, but if it is, I want to find out how. Basically, I want to create a Map where the key is a class (java.lang.Class),
This isn't possible due to type erasure.
However, you could subclass HashMap and write some logic into the put method which will do this for you:
public void put(K key, V value) {
if ( // value is an instance of key using .getClass()) {
super.put(key, value)
}
throw new Exception();
}
(Code for illustrative purposes only)