Here you can find the source of getGenericElementType(Field field)
public static Class getGenericElementType(Field field)
//package com.java2s; /*//from w w w. j av a 2 s . c om * Copyright (c) 1998 - 2005 Versant Corporation * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Versant Corporation - initial API and implementation */ import java.lang.reflect.Field; import java.lang.reflect.Method; public class Main { /** * Are we running on jdk 1.5 or higher? */ private static boolean isJDK_1_5 = false; /** * Get the element type for a Collection if possible using the JDK 1.5 * generics API or null if not possible. */ public static Class getGenericElementType(Field field) { return getType(field, 0); } /** * Get the class type of Collections and Maps with jdk1.5 generics if at all * possible */ private static Class getType(Field field, int index) { if (isJDK_1_5) { // do reflection on the jdk1.5 reflection methods Class clazz = null; try { Class tmp = /*CHFC*/field.getClass()/*RIGHTPAR*/; Method methodGetGenericType = tmp.getMethod("getGenericType", new Class[] {}); if (methodGetGenericType == null) return null; Object type = methodGetGenericType.invoke(field, new Object[] {}); if (type == null) return null; tmp = /*CHFC*/type.getClass()/*RIGHTPAR*/; Method methodActualTypeArguments = tmp.getMethod("getActualTypeArguments", new Class[] {}); if (methodActualTypeArguments == null) return null; Object typeArray = methodActualTypeArguments.invoke(type, new Object[] {}); if (typeArray == null) return null; Object[] types = (Object[]) typeArray; clazz = (Class) types[index]; } catch (Exception e) { /*hide it all*/ } return clazz; } else { return null; } } }