私はこのようなモデル構造を実装しようとしています:
Generic (abstract)
TplInsurance (extends Generic)
TplInsuranceDoctor (nested class in TplInsurance extends TplInsurance)
残念ながらTplInsuranceDoctor
、ネストされたクラスであるのオブジェクトを作成しようとすると、実行時エラーが発生します。
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
そのエラーはジェネリック コンストラクターを指します。
public Generic() {
entityClass = ((Class) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
}
モデルクラスは次のとおりです。
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";
}
オブジェクトを作成する方法は次のとおりです。
TplInsuranceDoctor tDoctor = new TplInsurance().new TplInsuranceDoctor();
入れ子になったクラスの型をどうにかしてパラメータ化する必要があることは理解していますが、そのTplInsuranceDoctor
方法はわかりません。私が試したものはすべてコンパイルに失敗しました。助けてください