Short version:
What is the correct syntax to make a class extends its generic argument:
class A<T> extends T {} // doesn't compile
Long version:
I have a base abstract class (the following code has been shortened just for this post purposes)
abstract class D {
abstract void f();
abstract void g();
}
Then, there is a set of possible combinations for each f() and each g(). The goal is to have all the possible combinations.
One solution is to make for each f_j() a class Fj that extends D and implements the f_j(), then for each g_i() we make a class GiFj which extends Fj and implements g_i(). For example
abstract class F1 extends D {
@Override
void f() { /* F1 Work */ }
}
abstract class F2 extends D {
@Override
void f() { /* F2 Work */ }
}
class G1F1 extends F1 {
@Override
void g() { /* G1 Work */ }
}
class G1F2 extends F2 {
@Override
void g() { /* G1 Work : Duplicated Code */ }
}
The problem is that the code for Gi is going to get duplicated many times.
The solution that I want to implement is to regroup all GFi into on generic class
class G1<F extends D> extends F {
@Override
void g() { /* G1 work */ }
}
So how to do this in java, or if it is impossible what is the good way to do it