Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm guessing you're talking about the use of extends in type parameter declarations. In that case:</p> <pre><code>class My_Abstract&lt;T extends SomeAbstract&gt; </code></pre> <p>has a bounded type parameter called <code>T</code> that must be <code>SomeAbstract</code> or some subtype of it.</p> <pre><code>class My_Abstract&lt;SomeAbstract&gt; </code></pre> <p>has an unbounded type parameter called <code>SomeAbstract</code> that could be anything. Note that <code>SomeAbstract</code> no longer refers to the actual type <code>SomeAbstract</code> that the first example uses at all!</p> <p>To expand on that: imagine if the second declaration were <code>class My_Abstract&lt;T&gt;</code>. The <code>T</code> there is clearly a type parameter, not an actual type. But it doesn't have to be called <code>T</code>... it can be called <code>E</code> or <code>Bob</code> or <code>SomeAbstract</code>. In all of these cases, it is still just a type parameter... an actual type can never go there, nor does it make any sense for it to (the whole point of a type parameter is to NOT refer to a specific type but instead allow other types to be put in its place when instances of the class are created).</p> <p>In the code you've edited in, change <code>My_Child</code>'s declaration to</p> <pre><code>class My_Child extends My_Abstract&lt;Object&gt; </code></pre> <p>and you'll see the difference. If you actually try to do something using the type parameter <code>SomeAbstract</code> in the second version, you'd also find that you cannot call any methods declared in the real <code>SomeAbstract</code> class. This is all a good example of why you should always follow the convention of using single-letter type parameters... it's really confusing if you don't.</p> <p>This is getting really long, but I also want to note that all of this is basically unrelated to the first half of your question. Wildcards like <code>? extends SomeAbstract</code> and <code>? super SomeAbstract</code> aren't used in type parameter declarations (such as those used when defining a generic class), they're primarily used for method parameters. <code>List</code> is a typical example for explaining why wildcards are needed because its nature as a container of objects makes it relatively easy to understand, but rules pertaining to them apply to any generic type. I tried to explain this in relatively general terms in <a href="https://stackoverflow.com/questions/2248390/java-generics-collections-max-signature-and-comparator/2248503#2248503">this answer</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. 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