I am trying to refactor the below code
class FileDownloadResource{ @Inject private FileDownload fileDownload; @Path(/abc) public Response downloadFileABC(){ try{ fileDownload.downloadABC(); }catch(IOException e){ } //Some code here that is common to the second method as well } @Path(/xyz) public Response downloadFileXYZ(){ try{ fileDownload.downloadXYZ(); }catch(IOException e){ //handle exception } //Some code here that is common to the first method as well } } The class is a JAX-RS rest resource. As you can see in the above code, everything except what is in the try block is the same for two method. Can we use any of the new JDK 8 features to pass fileDownload.downloadABC() as an argument to a private method ?
Basically, I am looking for some way to pass a function as an argument and let the other part of the code be same.