Java.lang.Class类 getGenericInterfaces()方法有什么功能呢?
下文讲述Class类中的getGenericInterfaces()方法的功能,如下所示:
用于返回类或接口直接实现的接口类型
getGenericInterfaces()方法的示例分享
getGenericInterfaces()方法的功能
java.lang.Class.getGenericInterfaces()方法的功能用于返回类或接口直接实现的接口类型
getGenericInterfaces()方法的语法
语法 public Type[] getGenericInterfaces() 参数 无 返回值 这个类中实现了接口的类型例:
getGenericInterfaces()方法的示例分享
package com.java.other;
import java.lang.reflect.Type;
import org.junit.Test;
public class other {
/**
* java265.com java.lang.Class 测试示例分享
*
* @throws Exception
*
*/
@Test
public void test() throws Exception {
Type[] t = Class.forName("java.util.HashMap").getGenericInterfaces();
if (t.length != 0) {
for (Type val : t) {
System.out.println(val.toString());
}
} else {
System.out.println("未实现任何接口");
}
}
}
--------运行以上代码, 将输出以下信息-----
java.util.Map<K, V>
interface java.lang.Cloneable
interface java.io.Serializable
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


