Search code examples
javagenericssuperextendsbounded-types

In Java type arguments, does <? extends E> mean strictly subtypes only? or would E also suffice?


In Java type arguments, does mean strictly subtypes only? or would E also suffice?


Solution

  • Yes, super and extends gives inclusive lower and upper bounds respectively.

    Here's a quote from Angelika Langer's Generics FAQ:

    What is a bounded wildcard?

    A wildcard with an upper bound looks like ? extends Type and stands for the family of all types that are subtypes of Type , type Type being included. Type is called the upper bound.

    A wildcard with a lower bound looks like ? super Type and stands for the family of all types that are supertypes of Type , type Type being included. Type is called the lower bound.