Java Reflection Generic Type from Class getGenericClass(Class clazz)

Here you can find the source of getGenericClass(Class clazz)

Description

get Generic Class

License

Open Source License

Declaration

public static Class<?> getGenericClass(Class<?> clazz) 

Method Source Code


//package com.java2s;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Main {

    public static Class<?> getGenericClass(Class<?> clazz) {
        Type t = clazz.getGenericSuperclass();
        if (t instanceof ParameterizedType) {
            Type[] p = ((ParameterizedType) t).getActualTypeArguments();
            return ((Class<?>) p[0]);
        }/*from   w  ww  .  j a  v  a 2s  .c o  m*/
        return null;
    }
}

Related

  1. getGenericClass(Class clazz)
  2. getGenericClass(Class clazz)
  3. getGenericClass(Class clazz)
  4. getGenericClass(Class clazz, int index)
  5. getGenericClass(Class clazz, int index)
  6. getGenericClass(Class clazz, int index)
  7. getGenericClass(Class cls)
  8. getGenericClass(final Class class1)
  9. getGenericClass(final Class parametrizedClass, int pos)