I have a list of exception handlers for specific exceptions which I am trying to define through a map that I can then access later to invoke. However, the .apply(e) is complaining that
'apply(capture<? extends java.lang.Exception>)' in 'java.util.function.Function' cannot be applied to '(java.lang.Exception)'
private Response handleException(Exception e) {
return HANDLERS.get(e.getClass()).apply(e);
}
Map<Class<? extends Exception>, Function<? extends Exception, Response>> HANDLERS =
Map.ofEntries(
Map.entry(SpecificException.class, (Function<SpecificException, Response>) e -> ...),
Map.entry(Exception.class, (Function<Exception, Response>) e -> ...)
);
I am sure this is a duplicate question but could not find anything related to solving this issue. Is there a solution to this specific error or is there another approach to this?