If you happen to know ConsumingHandler
is the only interface AtomEntryHandler
implements, and you happen to know it takes just one type argument, you can do this:
interface ConsumingHandler<T> {}
class AtomEntry {}
class AtomEntryHandler implements ConsumingHandler<AtomEntry>
{
public static void main( String[] args )
{
Type[] interfaces = AtomEntryHandler.class.getGenericInterfaces();
ParameterizedType firstInterface = (ParameterizedType) interfaces[0];
Class c = (Class) firstInterface.getActualTypeArguments()[0];
System.out.println(c.getName()); // prints "AtomEntry"
}
}
Otherwise, you can poke around in getGenericInterfaces()
and their actualTypeArguments
until you find something that looks like what you're looking for.
But if you find yourself needing to do this in real code, either something's probably gone badly wrong in your design, or you're writing some mad genius mock object library and you shouldn't need us to answer these questions.