Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The hard thing about the wildcard is to realize <code>? extends Foo</code> does not mean "anything that extends Foo", but instead it means "some specific type that extends Foo". And since you are outside that definition, you have no way to know <em>which</em> specific sub-type of <code>Foo</code> it is.</p> <p>Update:</p> <p>As I said, it's complicated. Here are some comments on your code.</p> <pre><code>// a list of some specific type, and you don't know what type that is. // it's a sub-type ob Object, yes, which means that you can do // Object foo = a.get(0); , but the compiler has no way of knowing // whether it's a String so you can't pass in a String List &lt;?&gt; a = new LinkedList&lt;Object&gt;(); // same here. '?' and '? extends Object' are equivalent List &lt;? extends Object&gt; b = new LinkedList&lt;Object&gt;(); // this is a list of Objects and superclasses thereof. // since there are no superclasses of Object, this is equivalent to // List&lt;Object&gt;. And through inheritance, a String is an Object, so // you can pass it in. List &lt;? super Object&gt; c = new LinkedList&lt;Object&gt;(); </code></pre> <p>Update 2:</p> <p>The problem here is that you are dealing with fixed, but unresolveable variables.</p> <pre><code>// you can pass in a List&lt;String&gt; and a String, // but if you pass in a List&lt;?&gt;, the compiler has no idea what // '?' is and just can't substitute 'String'. // 'T' doesn't help you here, because 'T' can't match both // '?' and 'String'. static &lt;T&gt; void abc(List&lt;T&gt; a, T b) {} // this works because 'T' substitutes '?' and doesn't have to worry // about a 2nd parameter static &lt;T&gt; void def(List&lt;T&gt; a) {} </code></pre> <p>Read this question, it might shed some light on the problem:</p> <p><a href="https://stackoverflow.com/questions/2723397/java-generics-what-is-pecs">What is PECS (Producer Extends Consumer Super)?</a></p>
    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.
 

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