Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Let us consider some deviations from this straigth-forward case. What if we defined the following methods in the subclass?

0
Posted

Let us consider some deviations from this straigth-forward case. What if we defined the following methods in the subclass?

0

Example (of a non-generic subtype with redefined supertype methods): class Super { … public void set( T arg) { … } … } class Sub extends Super { … public void set( Object arg) { … } // error: same erasure public void set( Long arg) { … } // overloads } The first set method in the subclass is rejected because it has the same erasure as its superclass’s version of the set method, namely void set(Object) . The second set method in the subclass is not override-equivalent, because its signature is truly different from the supertype method’s signature; they have a different argument type. For this reason it overloads the set method, instead of overriding it.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123