Let's get takeout project steps 14 and 15


I’ve been working at this for about a week. The interface “intUserInputRetriever” returns a T object from the one function it defines. When I try to implement it into the getOutputOnIntInput method, it seems that whatever I do it doesn’t allow me to return a generic object that can be used for the next few steps.

 private <T> T getOutputOnIntInput(String userInputPrompt, IntUserInputRetriever intUserInputRetriever){
    if (input.hasNextInt() == true){
      int num = input.nextInt();
      }catch(IllegalArgumentException e){
        System.out.println(num+ "is not a valid input");
    } else {
      System.out.println("Input must be an int");

What I have right now compiles without any errors other than a missing return type. But the “intUserInputRetriever” function needs to be turned into a T object that can be returned.

You can just return what you have in your try block and cast it to T:

return (T) intUserInputRetriever.produceOutputOnIntUserInput(num);