Here you can find the source of getGenericType(Field field)
public static Class getGenericType(Field field)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.util.Collection; public class Main { public static Class getGenericType(Field field) { if (!Collection.class.isAssignableFrom(field.getType())) { return field.getType(); }/*from w ww . j a v a 2 s . c o m*/ ParameterizedType type = (ParameterizedType) field.getGenericType(); return (Class) type.getActualTypeArguments()[0]; } public static Class getGenericType(Method method) { if (!Collection.class.isAssignableFrom(method.getReturnType())) { return method.getReturnType(); } ParameterizedType type = (ParameterizedType) method.getGenericReturnType(); return (Class) type.getActualTypeArguments()[0]; } }