Java Reflection Generic Parameter getGeneric(ParameterizedType type)

Here you can find the source of getGeneric(ParameterizedType type)

Description

get Generic

License

LGPL

Declaration

@SuppressWarnings("rawtypes")
public static Class[] getGeneric(ParameterizedType type) 

Method Source Code

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

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

public class Main {

    @SuppressWarnings("rawtypes")
    public static Class[] getGeneric(ParameterizedType type) {
        try {/* w w w.j  a  v a 2s  . c  o  m*/
            if (type != null) {
                Type[] typeArgs = type.getActualTypeArguments();
                if (typeArgs != null && typeArgs.length > 0) {
                    Class[] args = new Class[typeArgs.length];
                    for (int i = 0; i < typeArgs.length; i++) {
                        Type arg = typeArgs[i];
                        args[i] = (Class) arg;
                    }
                    return args;
                }
            }
        } catch (Exception e) {
        }
        return null;
    }
}

Related

  1. getGenericParameter(final Type type)
  2. getGenericParameter(final Type type, final int index)
  3. getGenericParameterList(Type type)
  4. getGenericParameters(final Type type)