Right now in some Java code I have something like this
class A {
void f() {
}
A() {
f();
}
}
class B extends A{
@Override
void f() {
//do some stuff
super.f();
}
}
class C extends B {
@Override
void f() {
//do some stuff
super.f();
}
}
I want to have f()
called and then iterate upwards through each parent class, running the overridden f()
. I do this by calling super.f()
explicitly, although I'd like to not have to do this.
The reason why I do this is there post processing that must be done after the constructor in A is reached. And there is state in each class that much be properly init'd, which is why we have the upward trace of f()
's.
So the constructor of A
is really
A() {
//init some state in a
f(); //run f(), which will depend on the previous operation
}
If I do something like new C();
I want C.f()
called, then B.f()
called, then A.f()
called
Anyway, if there is a smarter way of doing this, I'm open to it.