Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The concept at work here is called <a href="http://docs.oracle.com/javase/tutorial/java/generics/erasure.html" rel="noreferrer"><em>type erasure</em></a>. <code>HashSet</code> defines a method <code>add(T)</code>, and you define a method <code>add(Object)</code>. At a glance one might think this is OK; that your method just overloads <code>add</code>. However, the erasure of <code>T</code> is <code>Object</code> and so the two have the same erased signature. </p> <p>Now, that would be fine if your method properly overrode the method from <code>HashSet</code>. But to do so you should be using <code>add(Integer)</code> and not <code>add(Object)</code>. You're not properly overriding the parent method, so instead it is reported as a conflict since a class cannot provide two methods with the same signature.</p> <p>Your <code>Abc</code> example follows the same reasoning. The two methods you declared have the same erased signature so they clash.</p> <h2>Further Reading</h2> <p>Angelika Langer Generics FAQ </p> <ul> <li><a href="http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ813" rel="noreferrer">When does a method override its supertype's method?</a></li> <li><a href="http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#Can%20a%20method%20of%20a%20non-generic%20subtype%20override%20a%20method%20of%20a%20generic%20supertype?" rel="noreferrer">Can a method of a non-generic subtype override a method of a generic supertype?</a></li> </ul>
 

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