Is it possible to call a static method of a subclass from a static method of the parent class?
class A {
static foo(){
// call subclass static method bar()
}
}
class B extends A {
static bar(){
// do something
}
}
B.foo()
Note:
I initially attempted this because subclasses of A would have functioned best as singletons in my specific context, and I wanted to implement the template method pattern within A.
It appears that obtaining a reference to a subclass from within a static context is not feasible, so I have resorted to exporting instances of subclasses of A which has proven to be just as effective. Thank you.
Update 2
While there are similarities (the other question does not pertain to subclassing), the reference, even within a static context, is this
. Thus, the following code will work:
static foo(){
this.bar();
}