I am trying to implement model structure like this:
Generic (abstract)
TplInsurance (extends Generic)
TplInsuranceDoctor (nested class in TplInsurance extends TplInsurance)
Unfortunatelly I am getting runtime error when I am trying to create object of TplInsuranceDoctor
, wich is nested class:
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
That errors points to Generic contructor:
public Generic() {
entityClass = ((Class) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
}
Here are model classes:
public abstract class Generic<T extends Generic> {
protected Class<T> entityClass;
public Generic() {
entityClass = ((Class) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
}
public Long id;
}
public class TplInsurance extends GenericDictionary<TplInsurance> {
public class TplInsuranceDoctor extends TplInsurance {
public final String color = "success";
public final String title = "lekarza i dentysty";
}
Here is The way I create object:
TplInsuranceDoctor tDoctor = new TplInsurance().new TplInsuranceDoctor();
I understand That I should somehow parametrise type of nested class TplInsuranceDoctor
, but I dont know how. Everything I've tried fail compilation. Please help