Why does this Java method appear to have two return types?

No, you don’t have two return types. It’s a generic method you are seeing.

  • <E extends Foo> → You are declaring a generic type for your method;
  • List<E> → This is your return type.

Your method can have a generic type E which is a subclass of Foo. The return type of the method is a List<Foo-or-any-subtype-of-Foo>.

Leave a Comment