集册 Java实例教程 获取类类型变量

获取类类型变量

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

401
获取类类型变量


//package com.nowjava;/*from N  o w  J a v a . c o m*/


import java.lang.reflect.TypeVariable;


public class Main {

    public static void main(String[] argv) throws Exception {

        Class classInstance = String.class;

        getClassTypeVariable(classInstance);

    }


    public static void getClassTypeVariable(Class<?> classInstance) {

        TypeVariable<?>[] tv;

        String x;

        tv = classInstance.getTypeParameters(); //warning: unchecked conversion

        for (int i = 0; i < tv.length; i++) {

            x = tv[i].getName(); // E,K,V...

            if (i == 0) //?//来自 nowjava.com - 时代Java

                System.out.print("<" + x);

            else

                //

                
展开阅读全文