Consider the following:
Map<Class<?>, Object> myMap = new HashMap<Class<?>, Object>(); Foo fooObject = New Foo(); myMap.put(fooObject.getClass(), fooObject)
java.lang.Class safe to use as a key for a
myMap.get(Foo.class) always return the values which I put like
myMap.put(fooObject.getClass(), fooObject)? Consider the software to have various classloaders and serialization mechanisms. Will it still be the same result? If not... What would be an alternative?
Off the top of my head, would there be any reason to just not use the string class names? E.g. instead use:
If you are paranoid that maybe there could be more than one
Foo class in scope, you could use the full canonical name: