mardi 17 juillet 2018

getActualTypeArguments with parent which get its parametrized type from the child

I've done some research before posting but with no concrete answer.

Is it possible to get Actual Type Arguments for the super class which get its parametrized type from its child? for example..

GenericSubclass<T> extends GenericClass<T>

By instantiating GenericSubclass as:

GenericSubclass<String> genericClass = new GenericSubclass<>();

and executing the below returns "T"

Type type = ((ParameterizedType)this.getClass().
           getGenericSuperclass()).getActualTypeArguments()[0];

But what I need is java.lang.String. Any comments are appreciated





Aucun commentaire:

Enregistrer un commentaire