vendredi 25 septembre 2015

Get a generic class field type with Java Reflections

I have the following class structure:

public class GenClass<T> {
    public T elem;
}

I use it in the following way:

public class Test {
    public GenClass<UUID> data;

Now I want to get the type of elem using the Field object of data(Test.class.getField("data")) But when I use getType to retrieve the class the Generic information is stripped away.

How can I map the generic Information from getGenericType to the class object to retrieve the field with a correct type?





Aucun commentaire:

Enregistrer un commentaire