Java.lang.Class类 getTypeParameters()方法有什么功能呢?
下文讲述Class类中的getTypeParameters()方法的功能,如下所示:
返回一个由 GenericDeclaration 通用声明的类型变量TypeVariable对象 组成的数组
getTypeParameters()方法的示例分享
getTypeParameters()方法的功能
java.lang.Class.getTypeParameters()方法的功能返回一个由 GenericDeclaration 通用声明的类型变量TypeVariable对象 组成的数组
getTypeParameters()方法的语法
语法 public TypeVariable<Class<T>>[] getTypeParameters() 参数 无 返回值 返回一个TypeVariable对象组成的数组 当无泛型类型,则返回一个长度为0的数组例:
getTypeParameters()方法的示例分享
package com.java.other;
import java.lang.reflect.TypeVariable;
import org.junit.Test;
public class other {
/**
* java265.com java.lang.Class 测试示例分享
*
* @throws Exception
*
*/
@Test
public void test() throws Exception {
Class c = Class.forName("java.util.HashMap");
TypeVariable tArr[] = c.getTypeParameters();
for (TypeVariable t : tArr) {
System.out.println(t);
}
}
}
-----------运行以上代码,将输出以下信息-----
K
V
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


