static < T > Class < T > getTypeParameter ( Class < ? > clazz , Class < ? super T > bound ) { Type t = checkNotNull ( clazz ) ; while ( t instanceof Class < ? > ) { t = ( ( Class < ? > ) t ) . getGenericSuperclass ( ) ; } /** * This is not guaranteed to work for all cases with convoluted piping * of type parameters: but it can at least resolve straight-forward * extension with single type parameter (as per [Issue-89]). And when it * fails to do that, will indicate with specific exception. */ if ( t instanceof ParameterizedType ) { Class < T > result = processParameterizedType ( bound , ( ParameterizedType ) t ) ; if ( result != null ) { return result ; } } throw new IllegalStateException ( "Cannot figure out type parameterization for " + clazz . getName ( ) ) ; }
Finds the type parameter for the given class which is assignable to the bound class .