I have a problem with Java Generics and I'm not sure if it's even possible what I want to get. Basically title says it all but let me give you an example. Currently I have something like this:
private static Map<Class<? extends Exception>, ExceptionTranslator<?>> MAP;
which is being used in a following way:
MAP.put(SomeException.class, new ExceptionTranslator<SomeException>());
But I would like to enforce a translator of the exception type passed as a key, something similar to what you do on methods:
<T extends Exception> Map<Class<T>, ExceptionTranslator<T>> MAP;
This of course is not a correct code and I guess my generics-foo is not strong enough for this. Is it even possible in Java?
<T extends Exception>generic in its definition?Map; you have to do your own wrapping with a method that enforces the type constraint.