Content deleted Content added
m ce |
|||
Line 89:
</source>
In order to be able to do both add objects of type <code>MyClass</code> to the list and iterate over it using a variable of type <code>MyClass</code>, a <code>List<MyClass></code> is needed, which is the only type of <code>List</code> that is both <code>List<? extends MyClass></code> and <code>List<? super MyClass></code><ref>[[Java syntax|Java syntax(Generics)]]</ref>.
The mnemonics PECS (Producer Extends, Consumer Super) from the book '''Effective Java''' by [[Joshua Bloch]] gives an easy way to remember when to use wildcards (corresponding to Covariance and Contravariance) in Java.
|