I would like to have a factory that inherits another one with both factories implementing same generic interface with different type that inherits one another:
class FactoryA implements FactoryI<A> {
// common code
...
A get() {
return new A();
}
}
class FactoryB extends FactoryA implements FactoryI<B> {
B get() {
return new B();
}
}
class B extends A {
}
FactoryI<T> {
T get()
}
But this gives me following compilation error:
'FactoryI' cannot be inherited with different type arguments: 'A' and 'B'
My first version did not have FactoryB inheriting from FactoryA and this was working fine. But it turns out that there is now common code between both factories that I want to reuse.
What is the best way to achieve this?