There is such an interface:

public interface MyListener<T> { void processor(String s, String s, T data); } 

I do so myListener.getClass().getGenericInterfaces() this string returns me the full type in this format MyListener<java.lang.String> I want to get myself the generic type java.lang.String

How can I get type <T> using reflection ?

    1 answer 1

    I found this way

     for (Type type : myListener.getClass().getGenericInterfaces()){ if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType)type; System.out.print("Raw type: " + pType.getRawType() + " - "); System.out.println("Type args: " + pType.getActualTypeArguments()[0]); } else { System.out.println("Type: " + field.getType()); } }