Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To add to the already good answers here:</p> <p><strong>Method arguments:</strong></p> <p><code>List&lt;? extends Foo&gt;</code></p> <p>good choice if you don't intend to alter the list, and only care that everything in the list is assignable to type 'Foo'. This way, the caller can pass in a List&lt;FooSubclass&gt; and your method works. Usually the best choice.</p> <p><code>List&lt;Foo&gt;</code></p> <p>good choice if you intend to add Foo objects to the list in your method. The caller may not pass in a List&lt;FooSubclass&gt;, as you intend to add a Foo to the List.</p> <p><code>List&lt;? super Foo&gt;</code></p> <p>good choice if you intend to add Foo objects to the list, and it's not important what else is in the list (ie, you are ok getting a List&lt;Object&gt; that contains a 'Dog' that has nothing to do with Foo).</p> <p><strong>Method return values</strong></p> <p>just like method arguments, but with the benefits reversed. </p> <p><code>List&lt;? extends Foo&gt;</code> </p> <p>Guarantees that everything in the returned List has type 'Foo'. It might be List&lt;FooSubclass&gt; though. Caller cannot add to the List. This is your go-to choice and the most common case by far.</p> <p><code>List&lt;Foo&gt;</code></p> <p>Just like List&lt;? extends Foo&gt; but also allows the caller to add to the List. Less common.</p> <p><code>List&lt;? super Foo&gt;</code></p> <p>allows the caller to add Foo objects to the List, but does not guarantee what will be returned from list.get(0)... it could be anything from Foo to Object. The only guarantee is that this won't be a list of 'Dog' or some other choice that would prevent list.add(foo) from being legal. Very rare use case.</p> <p>I hope that helps. Good luck!</p> <p>ps. To sum up... two questions... </p> <blockquote> <p>do you need to add to the List? Do you care what is in the list?</p> <p>yes yes - use List&lt;Foo&gt;.</p> <p>yes no - use List&lt;? super Foo&gt;.</p> <p>no yes - use &lt;? extends Foo&gt; --- most common.</p> <p>no no - use &lt;?&gt;.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload