I have a parent class, which defines a collection of chainer methods (methods that return "this"). I want to define multiple child classes that contain their own chainer methods but that also "override" the parent methods so that an instance of the child class is returned instead of the parent class.
I don't want to have to repeat the same methods in each child class, which is why I have a parent class that contains the methods that all the child classes share. Thanks.
class Chain {
public Chain foo(String s){
...
return this;
}
}
class ChainChild extends Chain {
//I don't want to add a "foo" method to each child class
/*
public ChildChain foo(String s){
...
return this;
}
*/
public ChainChild bar(boolean b){
...
return this;
}
}
ChainChild child = new ChainChild();
child.foo().bar(); //compile error: foo() returns a "Chain" object which does not define the bar() method.