Skip to content

Instantly share code, notes, and snippets.

@kelunik
Created May 22, 2023 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelunik/f69d5c7c5d63ca0f02ea705e8f31ef5d to your computer and use it in GitHub Desktop.
Save kelunik/f69d5c7c5d63ca0f02ea705e8f31ef5d to your computer and use it in GitHub Desktop.

Given you have the following classes:

interface GenericInterface<T> {
   default List<T> returnGenericList() {
      return List.of();
   }
}

// Note: T isn't the same as in GenericInterface
interface Service<T> extends GenericInterface<String> {
   class Impl implements Service<Long> {

   }
}

Resolve the generic return type of Impl.returnGenericList via reflection.

Expected result: java.util.List<String>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment