I don't know if this is at all possible, but I was thinking of something in Java:
If I have an abstract parent class, I can do this:
public ParentClass add(ParentClass a, ParentClass b);
If ParentClass
then has a child and I want to override this method, the child class will still have a ParentClass add(ParentClass, ParentClass)
method.
Is there a way to make the parent function derive itself to each child?
I don't know if I'm wording it right, but something like this:
// ParentClass.java
public ParentClass add(ParentClass a, ParentClass b);
// Foo.java
@Override // or an equivalent
public Foo add(Foo a, Foo b) {}
// Bar.java
@Override
public Bar add(Bar a, Bar b) {}
Notice how each child doesn't have a ParentClass add(...)
function, but rather one for each of their own types instead?
Obviously I can just make these myself, but I want to be able to create overridable ones in parents. I've never seen this in practice before, so I doubt its existence. I just want to clarify with someone with a higher Java knowledge than me. Thanks.
In theory, which I guess no language has ever done, something like this:
public child add(child a, child b);
// where *child* is the type of the child inheriting the method