The following code is a common construct used with spring framework. The purpose it to provide configuration class that itself provides the required implementation classes, here AsyncUncaughtExceptionHandler.
Is it possible/advisable to refactor this code using the new java 1.8 lambda expressions? If yes, how?
@Component
public class AsyncConfigurer extends AsyncConfigurerSupport {
@Autowired
private CustomService service;
@Autowired
private Logger logger;
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new AsyncUncaughtExceptionHandler() {
@Override
public void handleUncaughtException(Throwable ex, Method method, Object... params) {
service.call();
logger.fatal(ex);
}
};
}
}
FunctionalInterfaces, which mine is NOT about!AsyncUncaughtExceptionHandleris a functional interface, otherwise the answer provided by Duncan (and the duplicate) would not work.