获取列表的元素类型
//package com.nowjava; import java.lang.reflect.GenericArrayType; /* *来 自 nowjava - 时代Java */ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.List; public class Main { public static Type getElementTypeOfList(final Type type) { if (!isTypeOf(type, List.class)) {/**来自 NowJava.com**/ return null; } return getGenericParameter(type, 0); } public static boolean isTypeOf(final Type type, final Class<?> clazz) { if (Class.class.isInstance(type)) { return clazz.isAssignableFrom(Class.class.cast(type)); } if (ParameterizedType.class.isInstance(type)) { final ParameterizedType parameterizedType = ParameterizedType.class .cast(type); return isTypeOf(parameterizedType.getRawType(), clazz); } return false; } public static Type[] getGenericParameter(final Type type) { if (ParameterizedType.class.isInstance(type)) { return ParameterizedType.class.cast(type) .getActualTypeArguments(); } if (GenericArrayType.class.isInstance(type)) { return getGenericParameter(GenericArrayType.class.cast(type) .getGenericComponentType()); } return null; } public static Type getGenericParameter(final Type type, final