Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * Resgata todos os generics da classe.
     * @param clazz Classe generics
     * @return Generic Type
     */
    public static Class<?>[] getTypeGenericsInstance(Class<?> clazz) {
        ParameterizedType parameterized = (ParameterizedType) clazz.getGenericSuperclass();
        Type[] arguments = parameterized.getActualTypeArguments();
        Class<?>[] classes = new Class[arguments.length];

        for (int i = 0; i < classes.length; i++) {
            classes[i] = (Class<?>) arguments[i];
        }
        return classes;
    }
}