Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let me start with example:</p> <pre><code>List&lt;DoesStuff&gt; a = new LinkedList&lt;DoesStuff&gt;; LinkedList&lt;DoesStuff&gt; b = new LinkedList&lt;DoesMoreStuff&gt;; //doesn't work. </code></pre> <p>In the second example if it was legal, you would be able to add <code>DoesStuff</code> objects into list of <code>DoesMoreStuff</code>.</p> <p>The trick is in your <code>DoesMoreStuff</code> you have type Paramter <code>E</code> which is not used and you've already explicitly set type parameter and have these methods:</p> <pre><code>public void MethodA(ArrayList&lt;DoesMoreStuff.ElementA&gt; moreElements) {} public void MethodB(ArrayList&lt;DoesMoreStuff.ElementA&gt; moreElements) {} </code></pre> <p>you can't overide them like this as described in the example above</p> <pre><code>@Override public void MethodA(ArrayList&lt;E&gt; moreElements) {} // as described in the example above </code></pre> <p><strong>Now coming to the third class:</strong></p> <pre><code>public class DoesEvenMoreStuff extends DoesMoreStuff&lt;DoesEvenMoreStuff.ElementB&gt; </code></pre> <p>type parameter <code>DoesEvenMoreStuff.ElementB</code> set <code>E</code> type parameter in superclass which is not used.</p> <p>Super class has these methods which you can override without changing type paramters as in the example in the beginning.</p> <pre><code>public void MethodA(ArrayList&lt;DoesMoreStuff.ElementA&gt; moreElements) {} public void MethodB(ArrayList&lt;DoesMoreStuff.ElementA&gt; moreElements) {} </code></pre> <p>Hope that helped to clarify things.</p>
 

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