In my code a there is the following abstract superclass
public abstract class AbstractClass<Type extends A> {...}
and some child classes like
public class ChildClassA extends AbstractClass<GenericTypeA> {...} public class ChildClassB extends AbstractClass<GenericTypeB> {...}
I am looking for an elegant way in which I can use the generic type of child classes (GenericTypeA, GenericTypeB, ...) inside an abstract class in a generic way.
To solve this problem, I have currently defined a method
protected abstract Class<Type> getGenericTypeClass();
in my abstract class and implemented a method
@Override protected Class<GenericType> getGenericTypeClass() { return GenericType.class; }
in each child class.
Is it possible to get the generic type of child classes in my abstract class without implementing this helper method?
BR
Marcus
java generics class abstract-class
Markus
source share