Java Reflection Generic Type from Class getGenerics(Class classType)

Here you can find the source of getGenerics(Class classType)

Description

get Generics

License

Apache License

Declaration

public static Class[] getGenerics(Class classType) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Main {

    public static Class[] getGenerics(Class classType) {
        Type type = (Type) classType.getGenericSuperclass();
        ParameterizedType pt = (ParameterizedType) type;
        Type[] types = pt.getActualTypeArguments();
        if (types[0] instanceof Class) {
            Class[] classz = new Class[types.length];
            for (int i = 0; i < classz.length; i++) {
                classz[i] = (Class) types[i];
            }/*from  ww w .  j av a 2  s  . c o m*/
            return classz;
        } else {
            return null;
        }
    }
}

Related

  1. getGenericParameterClass(Class actualClass, int parameterIndex)
  2. getGenericParameterClass(Class clazz)
  3. getGenericParameters(Class clazz)
  4. getGenericParameterType(Class clazz, Integer parameterIndex)
  5. getGenericParameterType0(Class cls, Class genericSuper, int paramIndex)
  6. getGenericsClass(Class cls)
  7. getGenericSuperclass(Class clazz)
  8. getGenericSuperclass(Class cls)
  9. getGenericSuperclassActualTypes(Collection types, Class aClass)