public static Type getGenericInterfaceType ( Object instance , Class < ? > iface , int position ) { Class < ? > type = instance . getClass ( ) ; while ( type != Object . class ) { for ( Type genericType : type . getGenericInterfaces ( ) ) { if ( genericType instanceof ParameterizedType ) { ParameterizedType parameterizedType = ( ParameterizedType ) genericType ; if ( parameterizedType . getRawType ( ) == iface ) { return parameterizedType . getActualTypeArguments ( ) [ position ] ; } } } type = type . getSuperclass ( ) ; } return null ; }
Returns the generic type at the given position for the given interface .