Let's get takeout project steps 14 and 15

https://www.codecademy.com/courses/learn-intermediate-java/projects/intermediate-java-collections-takeout

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){
      System.out.println(userInputPrompt);
      int num = input.nextInt();
      try{
        intUserInputRetriever.produceOutputOnIntUserInput(num);
      }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);