List of utility methods to do Reflection Generic Type from Class
Type[] | getGenericTypes(Class> clazz) get Generic Types Class<?> myClass = clazz; if (!(clazz.getGenericSuperclass() instanceof ParameterizedType)) { myClass = clazz.getSuperclass(); Type superClass = myClass.getGenericSuperclass(); ParameterizedType type = (ParameterizedType) superClass; return type.getActualTypeArguments(); |
Type[] | getGenericTypes(final Class> iClass) Returns the declared generic types of a class. final Type genericType = iClass.getGenericInterfaces()[0]; if (genericType != null && genericType instanceof ParameterizedType) { final ParameterizedType pt = (ParameterizedType) genericType; if (pt.getActualTypeArguments() != null && pt.getActualTypeArguments().length > 1) return pt.getActualTypeArguments(); return null; |
void | getGenericTypesImpl(ParameterizedType ptype, List get Generic Types Impl for (Type t : ptype.getActualTypeArguments()) { if (t instanceof Class) { classes.add((Class<?>) t); } else if (t instanceof ParameterizedType) { ParameterizedType next = (ParameterizedType) t; classes.add((Class<?>) next.getRawType()); getGenericTypesImpl(next, classes); return; |