Content deleted Content added
Remove duplicate citations. |
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation) |
||
Line 450:
In the common case of a generic data structure {{C sharp|IList}}, covariant parameters are used for methods getting data out of the structure, and contravariant parameters for methods putting data into the structure. The mnemonic for Producer Extends, Consumer Super (PECS), from the book ''Effective Java'' by [[Joshua Bloch]] gives an easy way to remember when to use covariance and contravariance.<ref name=Bloch />{{rp|141}}
Wildcards are flexible, but there is a drawback. While use-site variance means that API designers need not consider variance of type parameters to interfaces, they must often instead use more complicated method signatures. A common example involves the {{Javadoc:SE|java/lang|Comparable}} interface.<ref name=Bloch />{{rp|66}} Suppose we want to write a function that finds the biggest element in a collection. The elements need to implement the {{java|compareTo}} method,<ref name=Bloch />{{rp|66}}
<syntaxhighlight lang="java">
|