集册 Java实例教程 获取超类通用类型

获取超类通用类型

欢马劈雪     最近更新时间:2020-01-02 10:19:05

683
获取超类通用类型

/*

 * Copyright 2014-2017 ZuoBian.com All right reserved. This software is the confidential and proprietary information of

 * ZuoBian.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only

 * in accordance with the terms of the license agreement you entered into with ZuoBian.com.

 *//**nowjava.com - 时  代  Java**/

//package com.nowjava;

import java.lang.reflect.ParameterizedType;

import java.lang.reflect.Type;


public class Main {

    public static Class getSuperClassGenericType(Class clazz) {

        return getSuperClassGenericType(clazz, 0);

    }


    public static Class getSuperClassGenericType(Class clazz, int index) {

        Type genericSuperclass = clazz.getGenericSuperclass();

        if (genericSuperclass == null) {

            return null;

        }

        if ((genericSuperclass instanceof ParameterizedType) == false) {

            return null;

        }
        /** 
         来自 时 代      J a v a   公   众 号 - nowjava.com**/

        ParameterizedType paramterizedType = (ParameterizedType) genericSuperclass;

        Type[] actualTypeArguments = paramterizedType

                .getActualTy
展开阅读全文