Java Reflection Generic Type from Class getGenericClass(final Class class1)

Here you can find the source of getGenericClass(final Class class1)

Description

get Generic Class

License

Open Source License

Declaration

private static Class<?> getGenericClass(final Class<?> class1) 

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 {
    private static Class<?> getGenericClass(final Class<?> class1) {
        final Type type = class1.getGenericSuperclass();

        return getGenericClass(type);
    }//from  ww w  . j  a va2 s  .  c  o m

    private static Class<?> getGenericClass(final Type type) {
        Class<?> result = null;

        if (type instanceof ParameterizedType) {
            final ParameterizedType pt = (ParameterizedType) type;
            final Type[] fieldArgTypes = pt.getActualTypeArguments();
            result = (Class<?>) fieldArgTypes[0];
        }

        return result;
    }
}

Related

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