Here you can find the source of getGenericTypeOfParameter(Class> clazz, String method, int parameterIndex)
public static Class<?> getGenericTypeOfParameter(Class<?> clazz, String method, int parameterIndex)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.util.HashSet; import java.util.Set; public class Main { public static Class<?> getGenericTypeOfParameter(Class<?> clazz, String method, int parameterIndex) { try {/*from www. j a v a 2s. co m*/ Method m = clazz.getMethod(method, new Class<?>[] { Set.class, int.class }); ParameterizedType type = (ParameterizedType) m.getGenericParameterTypes()[parameterIndex]; return (Class<?>) type.getActualTypeArguments()[0]; } catch (Exception e) { try { Method m = clazz.getMethod(method, new Class<?>[] { HashSet.class, int.class }); ParameterizedType type = (ParameterizedType) m.getGenericParameterTypes()[parameterIndex]; return (Class<?>) type.getActualTypeArguments()[0]; } catch (Exception ex) { ex.printStackTrace(); } } return null; } }