Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.util.Collection; public class Main { static Class<? extends Object> getFieldClass(Field field) { return isCollection(field) ? getParametricClass(field) : field.getType(); } static boolean isCollection(Field field) { return Collection.class.isAssignableFrom(field.getType()); } static Class<?> getParametricClass(Class<?> clazz) { ParameterizedType paramType = (ParameterizedType) clazz.getGenericSuperclass(); return getParametricClass(paramType); } static Class<?> getParametricClass(Field field) { ParameterizedType paramType = (ParameterizedType) field.getGenericType(); return getParametricClass(paramType); } private static Class<?> getParametricClass(ParameterizedType parametType) { return (Class<?>) parametType.getActualTypeArguments()[0]; } }