lundi 9 avril 2018

Getting class of parameter of super interface of superclass

I am having some troubles getting the parameter of an abstract superclass implementing a parametric interface.

I have these classes and interface:

interface Request<T extends Bean>

abstract class ProxyRequest<T extends Bean> implements Request<T>

class FooRequest extends ProxyRequest<Foo>

What I'm trying to achieve is to get Foo.class starting from a FooRequest instance.

I'm trying this but the result is T. What am I doing wrong?

FooRequest request = new FooRequest();
Type[] genericInterfaces = request.getClass().getSuperclass().getGenericInterfaces();
Type[] genericTypes = ((ParameterizedType)genericInterfaces[0]).getActualTypeArguments();
System.out.println(genericTypes[0]);





Aucun commentaire:

Enregistrer un commentaire