Java Reflection Generic Type from Class getGenericType(Class type)

Here you can find the source of getGenericType(Class type)

Description

get Generic Type

License

Open Source License

Declaration

public static <T> T getGenericType(Class<?> type) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static <T> T getGenericType(Class<?> type) {
        assert type != null;

        ParameterizedType genericSuperclass = (ParameterizedType) type.getGenericSuperclass();

        Type[] actualTypeArguments = genericSuperclass.getActualTypeArguments();

        return (T) actualTypeArguments[0];
    }/* ww  w  . j  a  va  2s  .  c om*/
}

Related

  1. getGenericType(Class propertyType)
  2. getGenericType(Class clazz)
  3. getGenericType(Class clazz)
  4. getGenericType(Class clazz, int index)
  5. getGenericType(Class target)
  6. getGenericType(Class type, Class clazz)
  7. getGenericType(Object o, Class declaringClass, int idx)
  8. getGenericType(Type type, Class rawType, int index)
  9. getGenericTypeArgument(Class clazz, int index)