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 {

    @SuppressWarnings("rawtypes")
    public static Class[] getGenericInterfaces(Class<?> clazz) {
        try {
            Type typeGeneric = clazz.getGenericInterfaces()[0];
            if (typeGeneric != null) {
                if (typeGeneric instanceof ParameterizedType) {
                    return getGeneric((ParameterizedType) typeGeneric);
                }
            }
        } catch (Exception e) {
        }
        return null;
    }

    @SuppressWarnings("rawtypes")
    public static Class[] getGeneric(ParameterizedType type) {
        try {
            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;
    }
}