java - Inheritance of model class with generic and inner classes -


i have implemented inheritance hierarchy: generic extended insurance witch contains inner (non static) class houseinsurance

generic class extended

public abstract class generic<t extends generic> {     public generic() {        entityclass = ((class) ((class) ((parameterizedtype) getclass().getgenericsuperclass()).getactualtypearguments()[0]));     } } 

class extend generic , have nested class extend outer (enclosing) class insurance

public class insurance extends generic<insurance> {    public class houseinsurance extends insurance {    } } 

unfortunately when trying create instance of inner class getting error:

classcastexception: java.lang.class cannot cast java.lang.reflect.parameterizedtype 

i suppose should add inner class declaration parameter type. not know how.

generic class extended many other classes , works. first inheritance inner class, think there problem.

please help. far getting compilation error.

i not sure when create instance of houseinsurance class class should entityclass refer to? giving both solutions:

if entityclass should point houseinsurance class use code:

public generic() {     type generictype = getclass().getgenericsuperclass();     if (generictype instanceof parameterizedtype) {         entityclass = ((class) ((class) ((parameterizedtype) generictype).getactualtypearguments()[0]));     }     else {         entityclass = getclass().getsuperclass();     } } 

and if entityclass should point insurance class use instead:

public generic() {     class cclass = getclass();     {         type generictype = cclass.getgenericsuperclass();          if (generictype instanceof parameterizedtype) {             entityclass = ((class) ((class) ((parameterizedtype) generictype).getactualtypearguments()[0]));         }         else {             cclass = cclass.getsuperclass();         }     } while (entityclass == null); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -