Say I have a parent interface/class like so
interface Parent {}
And a number of implementing interfaces that fix the generic type.
Yes, despite what the others have said, this info is available if you have access to the subclass' Class
object. You need to use getGenericSuperclass
along with getActualTypeArguments
.
ParameterizedType superClass = (ParameterizedType)childClass.getGenericSuperclass();
System.out.println(superClass.getActualTypeArguments()[0]);
In your example, the "actual" type argument should return the Class
for Type
.