获取泛型转过来的类
public Class getGenericType(int index) { Type genType = getClass().getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { throw new RuntimeException("Index outof bounds"); } if (!(params[index] instanceof Class)) { return Object.class; } return (Class) params[index]; }
例如:Class<T,E>;T为0索引