列出接口在Java中扩展的接口
可以使用java.lang.Class.getInterfaces()方法确定由对象表示的接口实现的接口。此方法返回该接口实现的所有接口的数组。
演示此的程序如下所示-
示例
package Test;
import java.lang.*;
import java.util.*;
public class Demo {
public static void main(String[] args) {
listInterfaces(java.util.List.class);
}
public static void listInterfaces(Class c) {
System.out.println("The interface is: " + c.getName());
Class[] interfaces = c.getInterfaces();
System.out.println("The Interfaces are: " + Arrays.asList(interfaces));
}
}输出结果
The interface is: java.util.List The Interfaces are: [interface java.util.Collection]
现在让我们了解上面的程序。
使用方法listInterfaces()中的java.util.List.class调用该方法main()。演示这的代码片段如下-
listInterfaces(java.util.List.class);
在方法中listInterfaces(),该方法getName()用于打印接口名称。然后,该方法getInterfaces()用于返回该接口实现的所有接口的数组。然后,使用Arrays.asList()打印此数组。演示这的代码片段如下-
System.out.println("The interface is: " + c.getName());
Class[] interfaces = c.getInterfaces();
System.out.println("The Interfaces are: " + Arrays.asList(interfaces));热门推荐
5 短祝福语简短暖心
10 结婚祝福语粤语大全简短
11 晚上祝福语女生文案简短
12 法语妈妈生日祝福语简短
13 药厂开工祝福语大全简短
14 蛋糕节日祝福语简短英文
15 跨年的生日祝福语简短
16 文案祝福语英文短句简短
17 在家聚餐婚礼祝福语简短
18 学生节祝福语大全简短