专业网站建设价格分析,广州建设网站是什么,网站建设费是否应当入无形资产,自定义wordpress首页标题一、getInterfaces 返回直接实现的接口#xff08;
由于编译擦除#xff0c;没有显示泛型参数#xff09; Class?[] getInterfaces() 确定此对象所表示的类或接口实现的接口。 确定此对象所表示的类或接口实现的接口。 如果此对象表示一个类
由于编译擦除没有显示泛型参数 Class?[] getInterfaces() 确定此对象所表示的类或接口实现的接口。
确定此对象所表示的类或接口实现的接口。 如果此对象表示一个类则返回值是一个数组它包含了表示该类所实现的所有接口的对象。数组中接口对象顺序与此对象所表示的类的声明的 implements 子句中接口名顺序一致。例如给定声明 class Shimmer implements FloorWax, DessertTopping { ... } 设 s 的值为 Shimmer 的一个实例表达式 s.getClass().getInterfaces()[0]; 的值为表示 FloorWax 接口的 Class 对象 s.getClass().getInterfaces()[1]; 的值为表示 DessertTopping 接口的 Class 对象。 如果此对象表示一个接口则该数组包含表示该接口扩展的所有接口的对象。数组中接口对象顺序与此对象所表示的接口的声明的 extends 子句中接口名顺序一致。 如果此对象表示一个不实现任何接口的类或接口则此方法返回一个长度为 0 的数组。 如果此对象表示一个基本类型或 void则此方法返回一个长度为 0 的数组。 返回该类所实现的接口的一个数组。二、getGenericInterface 返回直接实现的接口包含泛型参数 Type[] getGenericInterfaces() 返回表示某些接口的 Type这些接口由此对象所表示的类或接口直接实现。
返回表示某些接口的 Type这些接口由此对象所表示的类或接口直接实现。
如果超接口是参数化类型则为它返回的 Type 对象必须准确反映源代码中所使用的实际类型参数。如果以前未曾创建表示每个超接口的参数化类型则创建这个类型。有关参数化类型创建过程的语义请参阅 ParameterizedType 声明。
如果此对象表示一个类则返回一个包含这样一些对象的数组这些对象表示该类实现的所有接口。数组中接口对象顺序与此对象所表示的类的声明的 implements 子句中接口名顺序一致。对于数组类接口 Cloneable 和 Serializable 以该顺序返回。
如果此对象表示一个接口则该数组包含表示该接口直接扩展的所有接口的对象。数组中接口对象顺序与此对象所表示的接口的声明的 extends 子句中接口名顺序一致。
如果此对象表示一个不实现任何接口的类或接口则此方法返回一个长度为 0 的数组。
如果此对象表示一个基本类型或 void则此方法返回一个长度为 0 的数组。 返回此类所实现的接口的一个数组抛出GenericSignatureFormatError - 如果常规类签名不符合 Java Virtual Machine Specification, 3rd edition 规定的格式TypeNotPresentException - 如果任意常规超接口引用不存在的类型声明MalformedParameterizedTypeException - 如果任意常规超接口引用的参数化类型由于某种原因无法实例化代码测试 package cn.test;import java.lang.reflect.Type;public class Test {public static void printInterface(Class?[] cs) {System.out.print(cs.length\t);for(Class? c :cs){System.out.print(c.getCanonicalName()\t);}System.out.println();}public static void printInterface(Type[] cs) {System.out.print(cs.length\t);for(Type c :cs){System.out.print(c.toString()\t);}System.out.println();}public static void main(String[] args) {//IStudentSystem.out.print(IStudent.class.getInterfaces()\t);printInterface(IStudent.class.getInterfaces()); System.out.print(IStudent.class.getGenericInterfaces()\t);printInterface(IStudent.class.getGenericInterfaces());//TestSystem.out.print(Test.class.getInterfaces()\t );printInterface(Test.class.getInterfaces());System.out.print(Test.class.getGenericInterfaces()\t);printInterface(Test.class.getGenericInterfaces());//ObjectSystem.out.print(Object.class.getGenericInterfaces()\t);printInterface(Object.class.getGenericInterfaces());System.out.print(Object.class.getInterfaces()\t );printInterface(Object.class.getInterfaces());//voidSystem.out.print(void.class.getInterfaces()\t);printInterface(void.class.getInterfaces());System.out.print(void.class.getGenericInterfaces()\t);printInterface(void.class.getGenericInterfaces());//int[]System.out.print(int[].class.getInterfaces()\t);printInterface(int[].class.getInterfaces());System.out.print(int[].class.getGenericInterfaces()\t);printInterface(int[].class.getGenericInterfaces());}}interface IPersonT {}
interface IWalkT {}
interface IStudent extends IPersonTest,IWalkObject,Cloneable{} 运行结果
IStudent.class.getInterfaces() 2 cn.test.IPerson cn.test.IWalk
IStudent.class.getGenericInterfaces() 3 cn.test.IPersoncn.test.Test cn.test.IWalkjava.lang.Object interface java.lang.Cloneable
Test.class.getInterfaces() 0
Test.class.getGenericInterfaces() 0
Object.class.getGenericInterfaces() 0
Object.class.getInterfaces() 0
void.class.getInterfaces() 0
void.class.getGenericInterfaces() 0
int[].class.getInterfaces() 2 java.lang.Cloneable java.io.Serializable
int[].class.getGenericInterfaces() 2 interface java.lang.Cloneable interface java.io.Serializable