I have an abstract class having an abstract method:
public abstract SomeClass Do(SomeClass o1, SomeClass o2);
Then when I implement in a concrete class which extends that abstract class which has the method from before it I get an error:
@Override
public AClass Do(AClass o1, AClass o2) //AClass extends Someclass
{
//
}
Why do I get the error since AClass is a subtype of SomeClass?
The error is: The method ... must override or implement a super-type method
You get an error because it doesn't support the same interface. Imagine a caller like this:
AbstractClass x = new ImplementingClass();
x.Do(new SomeClass(), new SomeClass());
That should work - it's just using the AbstractClass
abstract method, right? But the values you're passing in aren't AClass
references, they're just SomeClass
references.
Your return type is okay, but the parameters you're declaring are "narrower" than the original API, so your method can't handle all the calls that the original method could, and so can't override it.
See more on this question at Stackoverflow