Thursday, November 12, 2015

Core Java : What is the difference between a wildcard bound and a type parameter bound?

A wildcard can have only one bound, while a type parameter can have several bounds. A wildcard can have a lower or an upper bound, while there is no such thing as a lower bound for a type parameter.
Wildcard bounds and type parameter bounds are often confused, because they are both called bounds and have in part similar syntax. […]
Syntax:
  type parameter bound     T extends Class & Interface1 &  & InterfaceN

  wildcard bound  
      upper bound          ? extends SuperType
      lower bound          ? super   SubType
A wildcard can have only one bound, either a lower or an upper bound. A list of wildcard bounds is not permitted.
A type parameter, in constrast, can have several bounds, but there is no such thing as a lower bound for a type parameter.

No comments:

Post a Comment