@ SuppressWarnings ( "rawtypes" ) public static Class inferParameterClass ( Class clazz , String methodName ) { Method [ ] methods = clazz . getMethods ( ) ; for ( Method method : methods ) { if ( method . getName ( ) . equals ( methodName ) && ! method . isBridge ( ) ) { Type [ ] types = method . getGenericParameterTypes ( ) ; for ( Type type : types ) { if ( type instanceof Class && ! ( ( Class ) type ) . isInterface ( ) ) { return ( ( Class ) type ) ; } } } } return null ; }
Given a concrete class and a method name it tries to infer the Class of the first parameter of the method