Problem
I would like to create a function (brilliantFunction) for a set of classes (SubClass1, SubClass2, SubClass3) which all decent from one super class (SuperClass).
- SuperClass has the static function doSth()
- Each sub class overrides this function differently
- brilliantFunction uses this static function from one of the sub classes through generics
My idea:
abstract class SuperClass {
static void doSth();
}
class SubClass1 extends SuperClass {
@override
static void doSth() {
... // does something
}
}
... // somewhat the same for SubClass2+3
and the part that does not work:
void brilliantFunction<T extends SuperClass> () {
T.doSth() // <-- This does not work :(
}
Seems like I am not the only one trying to do it. And this person is asking sth differently. So apparently it actually should work just as I thought?