一、链接class类5种方式
1、实例类.getClass()
方法名:实例类.getClass()
方法参数:null
返回类型:Class<?>
方法说明:1、通过创建实例对象,获取当前对象的class对象
举例:
class class_students.TReflect
c.explain(1,
"实例类.getClass()",
null,
"Class<?>",
"1、通过创建实例对象,获取当前对象的class对象");
System.out.println("\t\t"+t.getClass());
System.out.println("\n\t-------------------------------------------------");
2、Class.forName(String className)
2、方法名:Class.forName(String className)
方法参数:String className
返回类型: Class<?>
方法说明:1、这是采用Class类的静态方法,
2、根据类名获取class对象,
3、需要try捕捉异常。
4、className 包名.类名,如果在src文件夹里创建的类,可以省略包名
举例:
class class_students.TReflect
c.explain(2,
"Class.forName(String className)",
"String className",
" Class<?>",
"1、这是采用Class类的静态方法,\n\t\t\t" +
"2、根据类名获取class对象,\n\t\t\t" +
"3、需要try捕捉异常。\n\t\t\t" +
"4、className 包名.类名,如果在src文件夹里创建的类,可以省略包名");
try {
System.out.println("\t\t"+Class.forName("class_students.TReflect"));
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
3、类名.class
3、方法名:类对象.class
方法参数:null
返回类型:Class<?>
方法说明:1、根据类名获取class对象。
举例:
class class_students.TReflect
c.explain(3,
"类对象.class",
null,
"Class<?>",
"1、根据类名获取class对象。" );
System.out.println("\t\t"+TReflect.class);
System.out.println("\n\t-------------------------------------------------");
4、类对象.ClassLoader().loadClass(指定包名.类)
4、方法名:类对象.ClassLoader().loadClass(指定包名.类)
方法参数:String className 指定类的包名.类
返回类型:Class<?>
方法说明:1、通过ClassLoader的loadClass方法,
2、指定类,其他类在同包内,可以省略其他类的包名,
3、如果在src文件夹里创建的类,可以省略指定类包名,
4、如果其他类在其他包里,则需要用Class.forName(其他类)来加载指定类.
举例:
1、其他类和指定类不在同包里,Class.forName("TestReflect") 例子:
class class_students.TReflect
2、其他类和指定类在同包里,Class_stu.class 例子:
class class_students.TReflect
c.explain(4,
"类对象.ClassLoader().loadClass(指定包名.类)",
"String className 指定类的包名.类",
"Class<?>",
"1、通过ClassLoader的loadClass方法,\n\t\t\t"+
"2、指定类,其他类在同包内,可以省略其他类的包名,\n\t\t\t"+
"3、如果在src文件夹里创建的类,可以省略指定类包名,\n\t\t\t"+
"4、如果其他类在其他包里,则需要用Class.forName(其他类)来加载指定类.");
try {
System.out.println("\t\t1、其他类和指定类不在同包里,Class.forName(\"TestReflect\") 例子:");
ClassLoader g = Class.forName("TestReflect").getClassLoader();
System.out.println("\t\t"+g.loadClass("class_students.TReflect"));
System.out.println("\n\t\t2、其他类和指定类在同包里,Class_stu.class 例子:");
ClassLoader g1 = Class_stu.class.getClassLoader();
System.out.println("\t\t"+g.loadClass("class_students.TReflect"));
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
5、基本数据类型的包装类.TYPE
5、方法名:基本数据类型的包装类.TYPE
方法参数:null
返回类型: Class<Integer>
方法说明:1、获取特殊class类对象,基本数据类型的包装类都有一个TYPE属性。
举例:
int
c.explain(5,
"基本数据类型的包装类.TYPE",
null,
" Class<Integer>",
"1、获取特殊class类对象,基本数据类型的包装类都有一个TYPE属性。");
System.out.println("\t\t"+Integer.TYPE);
System.out.println("\n\t===============================================\n");
二、class类方法的使用
1、public T newInstance()
1、方法名:public T newInstance() throws InstantiationException, IllegalAccessException
方法参数:null
返回类型:T
方法说明:1、需要try捕捉异常,
2、通过类对象创建类对象的实例。
3、如果不是TReflect.class.newInstance(),则需要强制声明强制转换关系
举例:
class_students.TReflect@74a14482
c.explain(1,
"public T newInstance() " +
"throws InstantiationException, IllegalAccessException",
null,
"T",
"1、需要try捕捉异常,\n\t\t\t" +
"2、通过类对象创建类对象的实例。\n\t\t\t" +
"3、如果不是TReflect.class.newInstance(),则需要强制声明强制转换关系" );
try {
TReflect newInstance=TReflect.class.newInstance();
System.out.println("\t\t"+TReflect.class.newInstance().toString());
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
2、public String toString()
2、方法名:public String toString()
方法参数:null
返回类型: String
方法说明:1、获取类对象的字符串表示。
举例:
class class_students.TReflect
c.explain(2,
"public String toString()",
null,
" String",
"1、获取类对象的字符串表示。");
System.out.println("\t\t"+t.getClass().toString());
System.out.println("\n\t-------------------------------------------------");
3、public String toGenericString()
3、方法名:public String toGenericString()
方法参数:null
返回类型: String
方法说明:1、获取类对象的字符串表示,
2、可以清楚知道这个类对象的修饰符和包名。
举例:
public class class_students.TReflect
c.explain(3,
"public String toGenericString()",
null,
" String",
"1、获取类对象的字符串表示,\n\t\t\t"+
"2、可以清楚知道这个类对象的修饰符和包名。");;
System.out.println("\t\t"+tC.toGenericString());
System.out.println("\n\t-------------------------------------------------");
4、public String getSimpleName()
4、方法名:public String getSimpleName()
方法参数:null
返回类型: String
方法说明:1、获取类对象的简单名称,
2、类是匿名的,则空。
举例:
1、class class_students.Class_stu$1匿名类 例子:
2、class class_students.Class_stu$1例子:TReflect
c.explain(4,
"public String getSimpleName()",
null,
" String",
"1、获取类对象的简单名称,\n\t\t\t"+
"2、类是匿名的,则空。");
//创建匿名类实例对象
OutClass d = new OutClass(){
public void toOutClassName(){
System.out.println("OutClass");
}
};
System.out.println("\t\t1、"+d.getClass()+"匿名类 例子:"+d.getClass().getSimpleName());
System.out.println("\t\t2、"+ d.getClass()+"例子:"+tC.getSimpleName());
System.out.println("\n\t-------------------------------------------------");
5、public String getName()
5、方法名:public String getName()
方法参数:null
返回类型: String
方法说明:1、获取类对象的名称。
举例:
class_students.TReflect
c.explain(5,
"public String getName()",
null,
" String",
"1、获取类对象的名称。");
System.out.println("\t\t"+tC.getName());
System.out.println("\n\t-------------------------------------------------");
6、public String getCanonicalName()
6、方法名:public String getCanonicalName()
方法参数:null
返回类型: String
方法说明:1、获取类对象的规范名称。
举例:
class_students.TReflect
c.explain(6,
"public String getCanonicalName()",
null,
" String",
"1、获取类对象的规范名称。");
System.out.println("\t\t"+tC.getCanonicalName());
System.out.println("\n\t-------------------------------------------------");
7、public String getTypeName()
7、方法名:public String getTypeName()
方法参数:null
返回类型: String
方法说明:1、获取类对象的类型名称。
举例:
class_students.TReflect
c.explain(7,
"public String getTypeName()",
null,
" String",
"1、获取类对象的类型名称。");
System.out.println("\t\t"+tC.getTypeName());
System.out.println("\n\t-------------------------------------------------");
8、public Package getPackage()
8、方法名:public Package getPackage()
方法参数:null
返回类型: Package
方法说明:1、获取类对象的包对象。
举例:
package class_students
c.explain(8,
"public Package getPackage()",
null,
" Package",
"1、获取类对象的包对象。");
System.out.println("\t\t"+tC.getPackage());
System.out.println("\n\t-------------------------------------------------");
9、public Class<?>[] getInterfaces()
9、方法名:public Class<?>[] getInterfaces()
方法参数:null
返回类型: Class<?>[]
方法说明:1、获取类对象的接口对象的数组。
举例:
class_students.TReflectInterface
class_students.TReflectInterface1
class_students.TReflectInterface2
c.explain(9,
"public Class<?>[] getInterfaces()",
null,
" Class<?>[]",
"1、获取类对象的接口对象的数组。");
for(Class<?> i : tC.getInterfaces()){
System.out.println("\t\t"+i.getName());
}
System.out.println("\n\t-------------------------------------------------");
10、public Class<? super T> getSuperclass()
10、方法名:public Class<? super T> getSuperclass()
方法参数:null
返回类型: Class<?>
方法说明:1、获取类对象的父类对象。2、如果没有父类对象,则为Object对象
举例:
class class_students.TReflectParentClass
c.explain(10,
"public Class<? super T> getSuperclass()",
null,
" Class<?>",
"1、获取类对象的父类对象。" +
"2、如果没有父类对象,则为Object对象");
System.out.println("\t\t"+tC.getSuperclass());
System.out.println("\n\t-------------------------------------------------");
11、public int getModifiers()
11、方法名:public int getModifiers()
方法参数:null
返回类型: int
方法说明:1、获取类对象的修饰符。
举例:
class_students.TReflect的修饰符:1
Modifier.isPublic(tC.getModifiers()) 结果:true
c.explain(11,
"public int getModifiers()",
null,
" int",
"1、获取类对象的修饰符。");
System.out.println("\t\t"+tC.getName()+"的修饰符:"+tC.getModifiers());
System.out.println("\t\t"+"Modifier.isPublic(tC.getModifiers()) 结果:"+Modifier.isPublic(tC.getModifiers()));
System.out.println("\n\t-------------------------------------------------");
12、public boolean isInterface()
12、方法名:public boolean isInterface()
方法参数:null
返回类型: boolean
方法说明:1、判断类对象是否是public接口类。
举例:
java.lang.Integer结果:false
java.lang.Comparable结果:true
c.explain(12,
"public boolean isInterface()",
null,
" boolean",
"1、判断类对象是否是public接口类。");
System.out.println("\t\t"+Integer.class.getName()+"结果:"+String.class.isInterface());
System.out.println("\t\t"+Comparable.class.getName()+"结果:"+Comparable.class.isInterface());
System.out.println("\n\t-------------------------------------------------");
13、public reflect.Type[] getGenericInterfaces()
13、方法名:public reflect.Type[] getGenericInterfaces()
方法参数:null
返回类型: reflect.Type[]
方法说明:1、获取类对象的泛型接口对象数组。
2、如果此类不实现任何接口,则返回一个长度为 0 的数组。
举例:
Non-generic interface: interface class_students.TReflectInterface
Non-generic interface: interface class_students.TReflectInterface1
Interface: interface class_students.TReflectInterface2
Type arguments: [class java.lang.String, class java.lang.Integer]
c.explain(13,
"public reflect.Type[] getGenericInterfaces()",
null,
" reflect.Type[]",
"1、获取类对象的泛型接口对象数组。\n\t\t\t" +
"2、如果此类不实现任何接口,则返回一个长度为 0 的数组。");
Type[] genericInterfaces = tC.getGenericInterfaces();
for (Type type : genericInterfaces) {
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
System.out.println("\t\t"+"Interface: " + pType.getRawType()); // 输出接口名
System.out.println("\t\t"+"Type arguments: " + Arrays.toString(pType.getActualTypeArguments())); // 输出泛型参数类型
} else {
System.out.println("\t\t"+"Non-generic interface: " + type);
}
}
System.out.println("\n\t-------------------------------------------------");
14、public reflect.Type getGenericSuperclass()
14、方法名:public reflect.Type getGenericSuperclass()
方法参数:null
返回类型: reflect.Type
方法说明:1、获取类对象的泛型父类对象。
2、如果此类没有父类,则返回 null。
举例:
class class_students.TReflectParentClass
c.explain(14,
"public reflect.Type getGenericSuperclass()",
null,
" reflect.Type",
"1、获取类对象的泛型父类对象。\n\t\t\t" +
"2、如果此类没有父类,则返回 null。");
System.out.println("\t\t"+tC.getGenericSuperclass());
System.out.println("\n\t-------------------------------------------------");
15、public reflect.TypeVariable<Class<T>>[] getTypeParameters()
15、方法名:public reflect.TypeVariable<Class<T>>[] getTypeParameters()
方法参数:null
返回类型: reflect.TypeVariable<Class<T>>[]
方法说明:1、获取类对象的泛型参数对象数组。
2、如果此类没有泛型参数,则返回一个长度为 0 的数组。
举例:
class_students.OutClass1的泛型参数:[T, K]
c.explain(15,
"public reflect.TypeVariable<Class<T>>[] getTypeParameters()",
null,
" reflect.TypeVariable<Class<T>>[]",
"1、获取类对象的泛型参数对象数组。\n\t\t\t" +
"2、如果此类没有泛型参数,则返回一个长度为 0 的数组。");
OutClass1<String, Integer> outClass1 = new OutClass1<String,Integer>();
System.out.println("\t\t"+outClass1.getClass().getName()+"的泛型参数:"+
Arrays.toString(outClass1.getClass().getTypeParameters()));
System.out.println("\n\t-------------------------------------------------");
16、public Class<?>[] getClasses()
16、方法名:public Class<?>[] getClasses()
方法参数:null
返回类型: Class<?>[]
方法说明:1、获取类对象的public内部类对象数组。
2、如果此类没有内部类,则返回一个长度为 0 的数组。
举例:
class_students.Class_stuOut2$Out2InnerClass2
class_students.Class_stuOut2$Out2InnerClass1
class_students.Class_stuOut2$Out2InnerClass
c.explain(16,
"public Class<?>[] getClasses()",
null,
" Class<?>[]",
"1、获取类对象的public内部类对象数组。\n\t\t\t" +
"2、如果此类没有内部类,则返回一个长度为 0 的数组。");
for(Class i :Class_stuOut2.class.getClasses()){
System.out.println("\t\t"+i.getName());
}
System.out.println("\n\t-------------------------------------------------");
17、public Class<?>[] getDeclaredClasses()
17、方法名:public Class<?>[] getDeclaredClasses() throws SecurityException
方法参数:null
返回类型: Class<?>[]
方法说明:1、获取类对象的所有内部类对象数组。
2、如果此类没有内部类,则返回一个长度为 0 的数组。
举例:
class_students.Class_stuOut2$Out2InnerClass4
class_students.Class_stuOut2$Out2InnerClass3
class_students.Class_stuOut2$Out2InnerClass2
class_students.Class_stuOut2$Out2InnerClass1
class_students.Class_stuOut2$Out2InnerClass
c.explain(17,
"public Class<?>[] getDeclaredClasses() " +
"throws SecurityException",
null,
" Class<?>[]",
"1、获取类对象的所有内部类对象数组。\n\t\t\t" +
"2、如果此类没有内部类,则返回一个长度为 0 的数组。");
for(Class i :Class_stuOut2.class.getDeclaredClasses()){
System.out.println("\t\t"+i.getName());
}
System.out.println("\n\t-------------------------------------------------");
18、public java.security.ProtectionDomain getProtectionDomain()
18、方法名:public java.security.ProtectionDomain getProtectionDomain()
方法参数:null
返回类型: java.security.ProtectionDomain
方法说明:1、获取类对象的保护域,
2、如果存在安全管理器,并且其 checkPermission 方法不允许获取 ProtectionDomain。,
3、信息太多了,用getPrincipals()隐藏了信息
举例:
[Ljava.security.Principal;@1540e19d
c.explain(18,
"public java.security.ProtectionDomain getProtectionDomain()",
null,
" java.security.ProtectionDomain",
"1、获取类对象的保护域,\n\t\t\t" +
"2、如果存在安全管理器,并且其 checkPermission 方法不允许获取 ProtectionDomain。,\n\t\t\t" +
"3、信息太多了,用getPrincipals()隐藏了信息");
System.out.println("\t\t"+tC.getProtectionDomain().getPrincipals());
System.out.println("\n\t-------------------------------------------------");
19、public java.io.InputStream getResourceAsStream(String name )
19、方法名:public java.io.InputStream getResourceAsStream(String name )
方法参数: String name
返回类型: java.io.InputStream
方法说明:1、由这个类对象作为类加载指定的资源,资源须在SRC包里。
2、如果此类没有指定名称的资源,则返回 null。
举例:
《静夜思》
唐朝李白
床前明月光,疑是地上霜。
举头望明月,低头思故乡。
c.explain(19,
"public java.io.InputStream getResourceAsStream(String name )",
" String name",
" java.io.InputStream",
"1、由这个类对象作为类加载指定的资源,资源须在SRC包里。\n\t\t\t" +
"2、如果此类没有指定名称的资源,则返回 null。");
try {
InputStream is=tC.getResourceAsStream("../srctest.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
System.out.println("\t\t"+line);
}
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
20、public java.net.URL getResource(String name )
20、方法名:public java.net.URL getResource(String name )
方法参数: String name
返回类型: java.net.URL
方法说明:1、由这个类对象作为类加载指定的资源,资源须在SRC包里。
2、如果此类没有指定名称的资源,则返回 null。
举例:
《静夜思》
唐朝李白
床前明月光,疑是地上霜。
举头望明月,低头思故乡。
c.explain(20,
"public java.net.URL getResource(String name )",
" String name",
" java.net.URL",
"1、由这个类对象作为类加载指定的资源,资源须在SRC包里。\n\t\t\t" +
"2、如果此类没有指定名称的资源,则返回 null。");
try {
URL url = tC.getResource("../srctest.txt");
//(InputStream) url.getContent() 这种也可以
BufferedReader reader =
new BufferedReader(new InputStreamReader(url.openStream()));
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
System.out.println("\t\t"+line);
}
}catch(Exception e){}
System.out.println("\n\t-------------------------------------------------");
21、public boolean desiredAssertionStatus()
21、方法名:public boolean desiredAssertionStatus()
方法参数:null
返回类型: boolean
方法说明:1、获取类对象的断言状态。
2、如果此类没有设置断言状态,则返回 false。3、下面列子利用加载类设置指定类的断言状态
举例:
class_students.Class_stuOut的断言状态:true
c.explain(21,
"public boolean desiredAssertionStatus()",
null,
" boolean",
"1、获取类对象的断言状态。\n\t\t\t" +
"2、如果此类没有设置断言状态,则返回 false。" +
"3、下面列子利用加载类设置指定类的断言状态");
try {
Class asaertTest = Class_stuOut.class;
tC.getClassLoader().setClassAssertionStatus("class_students.Class_stuOut", true);
System.out.println("\t\t"+asaertTest.getName()+"的断言状态:"+asaertTest.desiredAssertionStatus());
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
22、public T[] getEnumConstants()
22、方法名:public T[] getEnumConstants()
方法参数:null
返回类型: T[]
方法说明:1、获取类对象的枚举常量数组。
2、如果此类没有枚举常量,则返回一个长度为 0 的数组。
举例:
class_students.Class_stu$Class_stuSeason的枚举常量:冬天季节、秋天季节、夏天季节、春天季节
c.explain(
22,
"public T[] getEnumConstants()",
null,
" T[]",
"1、获取类对象的枚举常量数组。\n\t\t\t" +
"2、如果此类没有枚举常量,则返回一个长度为 0 的数组。"
);
String seasonName="" ;
for (Class_stuSeason s : Class_stuSeason.class.getEnumConstants()){
seasonName = s.seasonName +"季节、"+seasonName;
}
seasonName=seasonName.substring(0, seasonName.length()-1);
System.out.println("\t\t"+Class_stuSeason.class.getName()+"的枚举常量:"+seasonName);
System.out.println("\n\t-------------------------------------------------");
23、public Class<?> getEnclosingClass() throws SecurityException
23、方法名:public Class<?> getEnclosingClass() throws SecurityException
方法参数:null
返回类型: Class<?>
方法说明:1、获取类对象的外部类对象(也叫封闭类)。
2、如果此类没有外部类,则返回 null。
举例:
class class_students.Class_stuOut
c.explain(
23,
"public Class<?> getEnclosingClass() " +
"throws SecurityException",
null,
" Class<?>",
"1、获取类对象的外部类对象(也叫封闭类)。\n\t\t\t" +
"2、如果此类没有外部类,则返回 null。"
);
System.out.println("\t\t"+Class_stuOut.OutInnerClass.class.getEnclosingClass());
System.out.println("\n\t-------------------------------------------------");
24、public reflect.Method getEnclosingMethod()
24、方法名:public reflect.Method getEnclosingMethod() throws SecurityException
方法参数:null
返回类型:Class<?>
方法说明:1、获取类对象的外部方法对象(也叫封闭方法)。
2、如果此类没有外部方法,则返回 null。3、下面例子现在外部类调用方法,让外部class成员获取方法里面的类。
举例:
class_students.Class_stuOut$1OutInnerClass1_1的外部方法内类调用.getEnclosingMethod()
结果:public static void class_students.Class_stuOut.getEncMethod()
c.explain(
24,
"public reflect.Method getEnclosingMethod() " +
"throws SecurityException",
null,
"Class<?>",
"1、获取类对象的外部方法对象(也叫封闭方法)。\n\t\t\t" +
"2、如果此类没有外部方法,则返回 null。" +
"3、下面例子现在外部类调用方法,让外部class成员获取方法里面的类。"
);
Class_stuOut.getEncMethod();
Class MethodinnerClass = Class_stuOut.obj_class;
System.out.println("\t\t"+MethodinnerClass.getName()+"的外部方法内类调用.getEnclosingMethod()" +
"\n\t\t结果:"+MethodinnerClass.getEnclosingMethod());
System.out.println("\n\t-------------------------------------------------");
25、public reflect.Constructor<?> getEnclosingConstructor() throws SecurityException
25、方法名:public reflect.Constructor<?> getEnclosingConstructor() throws SecurityException
方法参数:null
返回类型:reflect.Constructor<?>
方法说明:1、获取类对象的外部构造方法对象(也叫封闭构造方法)。
2、如果此类没有外部构造方法,则返回 null。3、下面例子现在外部类调用构造方法,让外部class成员获取方法里面的类。
举例:
class_students.Class_stuOut$1OutConstructorInnerClass1的外部构造方法内类调用.getEnclosingClass()
结果:public class_students.Class_stuOut(java.lang.String)
c.explain(
25,
"public reflect.Constructor<?> getEnclosingConstructor() " +
"throws SecurityException",
null,
"reflect.Constructor<?>",
"1、获取类对象的外部构造方法对象(也叫封闭构造方法)。\n\t\t\t" +
"2、如果此类没有外部构造方法,则返回 null。" +
"3、下面例子现在外部类调用构造方法,让外部class成员获取方法里面的类。");
Class_stuOut cECon = new Class_stuOut("构造类调用");
Class cecclass = cECon.obj_class_Constr;
System.out.println("\t\t"+cecclass.getName()+"的外部构造方法内类调用.getEnclosingClass()" +
"\n\t\t结果:"+cecclass.getEnclosingConstructor());
System.out.println("\n\t-------------------------------------------------");
26、public ClassLoader getClassLoader()
26、方法名:public ClassLoader getClassLoader()
方法参数:null
返回类型:ClassLoader
方法说明:1、获取类对象的ClassLoader对象。
举例:
class_students.TReflect的ClassLoader对象 :sun.misc.Launcher$AppClassLoader@18b4aac2
c.explain(
26,
"public ClassLoader getClassLoader()",
null,
"ClassLoader",
"1、获取类对象的ClassLoader对象。"
);
System.out.println("\t\t"+tC.getName()+"的ClassLoader对象 :"+tC.getClassLoader());
System.out.println("\n\t-------------------------------------------------");
27、public <U> Class<? extends U> asSubclass( Class<U> clazz )
27、方法名:public <U> Class<? extends U> asSubclass( Class<U> clazz )
方法参数:Class<U> clazz
返回类型:<U> Class<? extends U>
方法说明:1、将此类对象转换为指定类的子类,即强制换声明关系,强制说明了这个类是指定类的子类。
2、如果此类对象不是指定类的子类,则抛出 ClassCastException。
3、下面例子将类转换为父类,让父类调用子类的构造方法。
举例:
Class dd =son1.asSubclass(father1) 强制申明了dd是TReflectParentClass的子类,
c.explain(
27,
"public <U> Class<? extends U> asSubclass( Class<U> clazz )",
"Class<U> clazz",
"<U> Class<? extends U>",
"1、将此类对象转换为指定类的子类,即强制换声明关系,强制说明了这个类是指定类的子类。\n\t\t\t" +
"2、如果此类对象不是指定类的子类,则抛出 ClassCastException。\n\t\t\t" );
Class father1 = TReflectParentClass.class;
Class son1 =TReflect.class;
Class dd =son1.asSubclass(father1);
try {
TReflect ef = (TReflect)dd.newInstance();
System.out.println("\t\tClass dd =son1.asSubclass(father1) 强制申明了dd是TReflectParentClass的子类," );
}catch(Exception e){};
System.out.println("\n\t-------------------------------------------------");
28、public Class<?> getComponentType()
28、方法名:public Class<?> getComponentType()
方法参数:null
返回类型:Class<?>
方法说明:1、获取数组的元素类型。
2、如果此类不是数组,则抛出 UnsupportedOperationException。
3、下面例子获取数组的元素类型。
举例:
[Ljava.lang.String;结果: class java.lang.String
java.lang.String结果: null
c.explain(
28,
"public Class<?> getComponentType()",
null,
"Class<?>",
"1、获取数组的元素类型。\n\t\t\t" +
"2、如果此类不是数组,则抛出 UnsupportedOperationException。\n\t\t\t" +
"3、下面例子获取数组的元素类型。"
);
System.out.println("\t\t"+String[].class.getName()+"结果: "+String[].class.getComponentType());
System.out.println("\t\t"+String.class.getName()+"结果: "+String.class.getComponentType());
System.out.println("\n\t-------------------------------------------------");
29、public T cast()
29、方法名:public T cast()
方法参数:null
返回类型:T
方法说明:1、将此类对象转换为指定的类型。
2、如果此类对象不是指定的类型,则抛出 ClassCastException。
3、下面例子将类转换为父类,让父类调用子类的构造方法。
举例:
强制转化为父类,但cft.class是子类的class 结果:class_students.Class_stuOutSon
c.explain(
29,
"public T cast()",
null,
"T",
"1、将此类对象转换为指定的类型。\n\t\t\t" +
"2、如果此类对象不是指定的类型,则抛出 ClassCastException。\n\t\t\t" +
"3、下面例子将类转换为父类,让父类调用子类的构造方法。"
);
Class_stuOutSon castFatherTest = new Class_stuOutSon();
Class_stuOutFather cft = (Class_stuOutFather)outSon.cast(castFatherTest);
System.out.println("\t\t强制转化为父类,但cft.class是子类的class 结果:"+cft.getClass().getName());
System.out.println("\n\t-------------------------------------------------");
30、public reflect.Field getField(String name) throws NoSuchFieldException, SecurityException
30、方法名:public reflect.Field getField(String name) throws NoSuchFieldException, SecurityException
方法参数:String name
返回类型:reflect.Field
方法说明:1、获取指定名称的public字段或父字段。
2、如果此类没有指定名称的字段,则抛出 NoSuchFieldException。
3、下面例子获取字段。
举例:
class_students.Class_stu的字段:Class_stu_i
class_students.Class_stuOutSon的父字段:father_i
c.explain(
30,
"public reflect.Field getField(String name) " +
"throws NoSuchFieldException, SecurityException",
"String name",
"reflect.Field",
"1、获取指定名称的public字段或父字段。\n\t\t\t" +
"2、如果此类没有指定名称的字段,则抛出 NoSuchFieldException。\n\t\t\t" +
"3、下面例子获取字段。"
);
try {
Field c_a = c.getClass().getField("Class_stu_i");
System.out.println("\t\t"+c.getClass().getName()+"的字段:"+c_a.getName());
Field son_fa = outSon.getField("father_i");
System.out.println("\t\t"+outSon.getName()+"的父字段:"+son_fa.getName());
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
31、public reflect.Field[] getFields() throws SecurityException
31、方法名:public reflect.Field[] getFields() throws SecurityException
方法参数:null
返回类型:reflect.Field[]
方法说明:1、获取此类所有public字段及父类public字段。
2、如果此类没有public字段,则返回一个长度为 0 的数组。
3、下面例子获取字段。
举例:
class_students.Class_stuOutSon的字段 :son_i
class_students.Class_stuOutSon的字段 :father_i
c.explain(
31,
"public reflect.Field[] getFields() " +
"throws SecurityException",
null,
"reflect.Field[]",
"1、获取此类所有public字段及父类public字段。\n\t\t\t" +
"2、如果此类没有public字段,则返回一个长度为 0 的数组。\n\t\t\t" +
"3、下面例子获取字段。"
);
for(Field f:outSon.getFields()){
System.out.println("\t\t"+outSon.getName()+"的字段 :"+f.getName());
}
System.out.println("\n\t-------------------------------------------------");
32、public reflect.Field[] getDeclaredFields() throws SecurityException
32、方法名:public reflect.Field[] getDeclaredFields() throws SecurityException
方法参数:null
返回类型:reflect.Field[]
方法说明:1、获取此类所有字段。
2、如果此类没有字段,则返回一个长度为 0 的数组。
3、下面例子获取字段。
举例:
class_students.Class_stuOutSon的字段 :son_i字段类型: int
字段修饰符: public static
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class_students.Class_stuOutSon的字段 :son_p字段类型: int
字段修饰符: private
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class_students.Class_stuOutSon的字段 :son_d字段类型: int
字段修饰符: protected
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c.explain(
32,
"public reflect.Field[] getDeclaredFields() throws SecurityException",
null,
"reflect.Field[]",
"1、获取此类所有字段。\n\t\t\t" +
"2、如果此类没有字段,则返回一个长度为 0 的数组。\n\t\t\t" +
"3、下面例子获取字段。"
);
Class_stuOutSon dso = new Class_stuOutSon();
for(Field f:outSon.getDeclaredFields()){
try {
System.out.println("\t\t"+outSon.getName()+"的字段 :"+f.getName()+"字段类型: "+f.getType().getName()
+ "\n\t\t字段修饰符: "+Modifier.toString(f.getModifiers()));
System.out.println("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}catch (Exception e) { }}
System.out.println("\n\t-------------------------------------------------");
33、public reflect.Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
33、方法名:public reflect.Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
方法参数:String name
返回类型:reflect.Field
方法说明:1、获取指定此类名称的字段。
2、如果此类没有指定名称的字段,则抛出 NoSuchFieldException。
3、下面例子获取字段。
举例:
class_students.Class_stuOutSon的字段:son_i
c.explain(
33,
"public reflect.Field getDeclaredField(String name) " +
"throws NoSuchFieldException, SecurityException",
"String name",
"reflect.Field",
"1、获取指定此类名称的字段。\n\t\t\t" +
"2、如果此类没有指定名称的字段,则抛出 NoSuchFieldException。\n\t\t\t" +
"3、下面例子获取字段。"
);
try {
Field dso_f = outSon.getDeclaredField("son_i");
System.out.println("\t\t"+outSon.getName()+"的字段:"+dso_f.getName());
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
34、public reflect.Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
34、方法名:public reflect.Constructor<T> getConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
方法参数:Class<?>... parameterTypes
返回类型:reflect.Constructor<T>
方法说明:1、获取指定参数类型的构造方法。
2、如果此类没有指定参数类型的构造方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public class_students.Class_stuOutSon(int)
c.explain(
34,
"public reflect.Constructor<T> getConstructor(Class<?>... parameterTypes) \n\t\t" +
"throws NoSuchMethodException, SecurityException",
"Class<?>... parameterTypes",
"reflect.Constructor<T>",
"1、获取指定参数类型的构造方法。\n\t\t\t" +
"2、如果此类没有指定参数类型的构造方法,则抛出 NoSuchMethodException。");
try {
Class_stuOutSon conc = new Class_stuOutSon(2);
Constructor con_c = outSon.getConstructor(int.class);
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+con_c);
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
35、public reflect.Constructor<?>[] getConstructors() throws SecurityException
35、方法名:public reflect.Constructor<?>[] getConstructors() throws SecurityException
方法参数:null
返回类型:reflect.Constructor<?>[]
方法说明:1、获取public类型的构造方法。
2、如果此类没有构造方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public class_students.Class_stuOutSon(int[])
class_students.Class_stuOutSon的构造方法:public class_students.Class_stuOutSon(int)
c.explain(
35,
"public reflect.Constructor<?>[] getConstructors() " +
"throws SecurityException",
null,
"reflect.Constructor<?>[]",
"1、获取public类型的构造方法。\n\t\t\t" +
"2、如果此类没有构造方法,则抛出 NoSuchMethodException。");
for(Constructor con:outSon.getConstructors()){
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+con);
}
System.out.println("\n\t-------------------------------------------------");
36、public reflect.Constructor<?>[] getDeclaredConstructors() throws SecurityException
36、方法名:public reflect.Constructor<?>[] getDeclaredConstructors() throws SecurityException
方法参数:null
返回类型:reflect.Constructor<?>[]
方法说明:1、获取所有构造方法。
2、如果此类没有构造方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public class_students.Class_stuOutSon(int[])
class_students.Class_stuOutSon的构造方法:protected class_students.Class_stuOutSon(int,int)
class_students.Class_stuOutSon的构造方法:public class_students.Class_stuOutSon(int)
class_students.Class_stuOutSon的构造方法:private class_students.Class_stuOutSon()
c.explain(
36,
"public reflect.Constructor<?>[] getDeclaredConstructors() " +
"throws SecurityException",
null,
"reflect.Constructor<?>[]",
"1、获取所有构造方法。\n\t\t\t" +
"2、如果此类没有构造方法,则抛出 NoSuchMethodException。");
for(Constructor con:outSon.getDeclaredConstructors()){
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+con);
}
System.out.println("\n\t-------------------------------------------------");
37、public reflect.Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
37、方法名:public reflect.Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
方法参数:Class<?>... parameterTypes
返回类型:reflect.Constructor<T>
方法说明:1、获取指定参数类型的构造方法。
2、如果此类没有指定参数类型的构造方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:private class_students.Class_stuOutSon()
c.explain(
37,
"public reflect.Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) \n\t\t" +
"throws NoSuchMethodException, SecurityException",
"Class<?>... parameterTypes",
"reflect.Constructor<T>",
"1、获取指定参数类型的构造方法。\n\t\t\t" +
"2、如果此类没有指定参数类型的构造方法,则抛出 NoSuchMethodException。");
try {
Constructor con_c = outSon.getDeclaredConstructor();
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+con_c);
}catch (Exception e) {}
System.out.println("\n\t-------------------------------------------------");
38、public reflect.Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
38、方法名:public reflect.Method getMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
方法参数:String name, Class<?>... parameterTypes
返回类型:reflect.Method
方法说明:1、获取指定public名称和参数类型的方法。
2、如果此类没有指定名称和参数类型的方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod()
c.explain(
38,
"public reflect.Method getMethod(String name, Class<?>... parameterTypes)\n\t\t " +
"throws NoSuchMethodException, SecurityException",
"String name, Class<?>... parameterTypes",
"reflect.Method",
"1、获取指定public名称和参数类型的方法。\n\t\t\t" +
"2、如果此类没有指定名称和参数类型的方法,则抛出 NoSuchMethodException。");
try {
Method m = outSon.getMethod("Class_stuOutSonMethod");
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+m);
}catch(Exception e){}
System.out.println("\n\t-------------------------------------------------");
39、public reflect.Method[] getMethods() throws SecurityException
39、方法名:public reflect.Method[] getMethods() throws SecurityException
方法参数:null
返回类型: reflect.Method[]
方法说明:1、获取所有public的此类方法和父方法。
2、如果没有此类方法和父方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod(int)
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod(int[])
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod()
class_students.Class_stuOutSon的构造方法:public static void class_students.Class_stuOutFather.father_method()
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutFather.father_method3(int[])
class_students.Class_stuOutSon的构造方法:public final void java.lang.Object.wait() throws java.lang.InterruptedException
class_students.Class_stuOutSon的构造方法:public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
class_students.Class_stuOutSon的构造方法:public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
class_students.Class_stuOutSon的构造方法:public boolean java.lang.Object.equals(java.lang.Object)
class_students.Class_stuOutSon的构造方法:public java.lang.String java.lang.Object.toString()
class_students.Class_stuOutSon的构造方法:public native int java.lang.Object.hashCode()
class_students.Class_stuOutSon的构造方法:public final native java.lang.Class java.lang.Object.getClass()
class_students.Class_stuOutSon的构造方法:public final native void java.lang.Object.notify()
class_students.Class_stuOutSon的构造方法:public final native void java.lang.Object.notifyAll()
c.explain(
39,
"public reflect.Method[] getMethods() " +
"throws SecurityException",
null,
" reflect.Method[]",
"1、获取所有public的此类方法和父方法。\n\t\t\t" +
"2、如果没有此类方法和父方法,则抛出 NoSuchMethodException。");
for(Method m:outSon.getMethods()){
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+m);
}
System.out.println("\n\t-------------------------------------------------");
40、public reflect.Method[] getDeclaredMethods() throws SecurityException
40、方法名:public reflect.Method[] getDeclaredMethods() throws SecurityException
方法参数:null
返回类型:reflect.Method[]
方法说明:1、获取此类所有方法。
2、如果此类没有方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod(int)
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod(int[])
class_students.Class_stuOutSon的构造方法:protected void class_students.Class_stuOutSon.Class_stuOutSonMethod(int,java.lang.String)
class_students.Class_stuOutSon的构造方法:private void class_students.Class_stuOutSon.Class_stuOutSonMethod(java.lang.String)
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod()
c.explain(
40,
"public reflect.Method[] getDeclaredMethods() " +
"throws SecurityException",
null,
"reflect.Method[]",
"1、获取此类所有方法。\n\t\t\t" +
"2、如果此类没有方法,则抛出 NoSuchMethodException。");
for(Method m:outSon.getDeclaredMethods()){
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+m);
}
System.out.println("\n\t-------------------------------------------------");
41、public reflect.Method getDeclaredMethod(String name,Class<?>... parameterTypes ) throws NoSuchMethodException, SecurityException
41、方法名:public reflect.Method getDeclaredMethod(String name,Class<?>... parameterTypes )
throws NoSuchMethodException, SecurityException
方法参数: String name,Class<?>... parameterTypes
返回类型:reflect.Method
方法说明:1、获取指定名称和参数类型的此类方法。
2、如果此类没有指定名称和参数类型的此类方法,则抛出 NoSuchMethodException。
举例:
class_students.Class_stuOutSon的构造方法:public void class_students.Class_stuOutSon.Class_stuOutSonMethod()
c.explain(
41,
"public reflect.Method getDeclaredMethod(String name,Class<?>... parameterTypes )\n\t\t" +
"throws NoSuchMethodException, SecurityException",
" String name,Class<?>... parameterTypes",
"reflect.Method",
"1、获取指定名称和参数类型的此类方法。\n\t\t\t" +
"2、如果此类没有指定名称和参数类型的此类方法,则抛出 NoSuchMethodException。"
);
try {
Method m = outSon.getDeclaredMethod("Class_stuOutSonMethod");
System.out.println("\t\t"+outSon.getName()+"的构造方法:"+m);
}catch (Exception e){}
System.out.println("\n\t-------------------------------------------------");
42、public <A extends annotation.Annotation> A getAnnotation(Class<A> annotationClass)
42、方法名:public <A extends annotation.Annotation> A getAnnotation(Class<A> annotationClass)
方法参数:Class<A> annotationClass
返回类型:A
方法说明:1、获取此类指定类型的public类注解。
2、如果此类没有指定类型的类注解,则返回 null。
3、如果此类有多个指定类型的类注解,则返回此类中最近的那个。
4、如果此类有多个指定类型的类注解,并且它们都没有指定元注解,则抛出 IllegalArgumentException。
举例:
class_students.Class_stuOutSon的指定注解信息 :@class_students.Author(name=owern, example=N/A)
c.explain(
42,
"public <A extends annotation.Annotation> A getAnnotation(Class<A> annotationClass)",
"Class<A> annotationClass",
"A",
"1、获取此类指定类型的public类注解。\n\t\t\t" +
"2、如果此类没有指定类型的类注解,则返回 null。\n\t\t\t" +
"3、如果此类有多个指定类型的类注解,则返回此类中最近的那个。\n\t\t\t" +
"4、如果此类有多个指定类型的类注解,并且它们都没有指定元注解,则抛出 IllegalArgumentException。");
System.out.println("\t\t"+outSon.getName()+"的指定注解信息 :"+ outSon.getAnnotation( Author.class) );
System.out.println("\n\t-------------------------------------------------");
43、public annotation.Annotation[] getAnnotations()
43、方法名:public annotation.Annotation[] getAnnotations()
方法参数:null
返回类型:annotation.Annotation[]
方法说明:1、获取此类所有public类注解。
举例:
class_students.Class_stuOutSon的类注解信息 :@class_students.Author(name=owern, example=N/A)
class_students.Class_stuOutSon的类注解信息 :@class_students.Target_TYPE_USE(name=ElementType_TYPE_USE, parametername=)
c.explain(
43,
"public annotation.Annotation[] getAnnotations()",
null,
"annotation.Annotation[]",
"1、获取此类所有public类注解。");
for(Annotation a:outSon.getAnnotations()){
System.out.println("\t\t"+outSon.getName()+"的类注解信息 :"+ a);
}
System.out.println("\n\t-------------------------------------------------");
44、public annotation.Annotation[] getDeclaredAnnotations()
44、方法名:public annotation.Annotation[] getDeclaredAnnotations()
方法参数:null
返回类型:annotation.Annotation[]
方法说明:1、获取此类所有类注解。
举例:
class_students.Class_stuOutSon的类注解信息 :@class_students.Author(name=owern, example=N/A)
class_students.Class_stuOutSon的类注解信息 :@class_students.Target_TYPE_USE(name=ElementType_TYPE_USE, parametername=)
c.explain(
44,
"public annotation.Annotation[] getDeclaredAnnotations()",
null,
"annotation.Annotation[]",
"1、获取此类所有类注解。");
for(Annotation a:outSon.getDeclaredAnnotations()){
System.out.println("\t\t"+outSon.getName()+"的类注解信息 :"+ a);
}
System.out.println("\n\t-------------------------------------------------");
45、public <A extends annotation.Annotation> A getDeclaredAnnotation( Class<A> annotationClass )
45、方法名:public <A extends annotation.Annotation> A getDeclaredAnnotation( Class<A> annotationClass )
方法参数:Class<A> annotationClass
返回类型:A
方法说明:1、获取此类指定类型的类注解。
2、如果此类没有指定类型的类注解,则返回 null。
3、如果此类有多个指定类型的类注解,则返回此类中最近的那个。
4、如果此类有多个指定类型的类注解,并且它们都没有指定元注解,则抛出 IllegalArgumentException。
举例:
class_students.Class_stuOutSon的指定注解信息 :@class_students.Author(name=owern, example=N/A)
c.explain(
45,
"public <A extends annotation.Annotation> A " +
"getDeclaredAnnotation( Class<A> annotationClass )",
"Class<A> annotationClass",
"A",
"1、获取此类指定类型的类注解。\n\t\t\t" +
"2、如果此类没有指定类型的类注解,则返回 null。\n\t\t\t" +
"3、如果此类有多个指定类型的类注解,则返回此类中最近的那个。\n\t\t\t" +
"4、如果此类有多个指定类型的类注解,并且它们都没有指定元注解,则抛出 IllegalArgumentException。");
System.out.println("\t\t"+outSon.getName()+"的指定注解信息 :"+ outSon.getDeclaredAnnotation( Author.class) );
System.out.println("\n\t-------------------------------------------------");
46、public reflect.AnnotatedType[] getAnnotatedInterfaces()
46、方法名:public reflect.AnnotatedType[] getAnnotatedInterfaces()
方法参数:null
返回类型:reflect.AnnotatedType[]
方法说明:1、获取此类所有public接口的AnnotatedType。
2、如果此类没有public接口,则返回一个长度为0的数组。
3、如果此类有多个public接口,则返回一个包含所有public接口的AnnotatedType的数组。
举例:
class_students.Class_stuOutSon的接口信息 :interface class_students.Class_stuOutSonInterface
c.explain(
46,
"public reflect.AnnotatedType[] getAnnotatedInterfaces()",
null,
"reflect.AnnotatedType[]",
"1、获取此类所有public接口的AnnotatedType。\n\t\t\t" +
"2、如果此类没有public接口,则返回一个长度为0的数组。\n\t\t\t" +
"3、如果此类有多个public接口,则返回一个包含所有public接口的AnnotatedType的数组。\n\t\t\t");
for(AnnotatedType a:outSon.getAnnotatedInterfaces()){
System.out.println("\t\t"+outSon.getName()+"的接口信息 :"+ a.getType());
}
System.out.println("\n\t-------------------------------------------------");
47、"public reflect.AnnotatedType getAnnotatedSuperclass()
47、方法名:public reflect.AnnotatedType getAnnotatedSuperclass()
方法参数:null
返回类型:reflect.AnnotatedType
方法说明:1、获取此类的AnnotatedType。
2、如果此类没有超类,则返回 null。
3、如果此类有多个超类,则返回此类中最近的那个。
举例:
class_students.Class_stuOutSon的超类信息 :class class_students.Class_stuOutFather
c.explain(
47,
"public reflect.AnnotatedType getAnnotatedSuperclass()",
null,
"reflect.AnnotatedType",
"1、获取此类的AnnotatedType。\n\t\t\t" +
"2、如果此类没有超类,则返回 null。\n\t\t\t" +
"3、如果此类有多个超类,则返回此类中最近的那个。\n\t\t\t");
System.out.println("\t\t"+outSon.getName()+"的超类信息 :"+ outSon.getAnnotatedSuperclass().getType());
System.out.println("\n\t-------------------------------------------------");
48、public <A extends annotation.Annotation> A[] getAnnotationsByType(Class<A> annotationClass )
48、方法名:public <A extends annotation.Annotation> A[] getAnnotationsByType(Class<A> annotationClass )
方法参数:Class<A> annotationClass
返回类型:A[]
方法说明:1、获取此类指定类型的public类注解。
2、如果此类没有指定类型的类注解,则返回一个长度为0的数组。
3、如果此类有多个指定类型的类注解,则返回一个包含所有指定类型的类注解的数组。
4、如果此类有多个指定类型的类注解,并且它们都没有指定元注解.
举例:
class_students.Class_stuOutSon的类注解信息 :interface class_students.Target_TYPE_USE
48、方法名:public <A extends annotation.Annotation> A[] getAnnotationsByType(Class<A> annotationClass )
方法参数:Class<A> annotationClass
返回类型:A[]
方法说明:1、获取此类指定类型的public类注解。
2、如果此类没有指定类型的类注解,则返回一个长度为0的数组。
3、如果此类有多个指定类型的类注解,则返回一个包含所有指定类型的类注解的数组。
4、如果此类有多个指定类型的类注解,并且它们都没有指定元注解.
举例:
class_students.Class_stuOutSon的类注解信息 :interface class_students.Target_TYPE_USE
49、public <A extends annotation.Annotation> A[] getDeclaredAnnotationsByType( Class<A> annotationClass )
49、方法名:public <A extends annotation.Annotation> A[] getDeclaredAnnotationsByType( Class<A> annotationClass )
方法参数:Class<A> annotationClass
返回类型:A[]
方法说明:1、此类所有类型类注解都可以指定获取。
2、如果此类没有指定类型的类注解,则返回一个长度为0的数组。
3、如果此类有多个指定类型的类注解,则返回一个包含所有指定类型的类注解的数组。
举例:
class_students.Class_stuOutSon的类注解信息 :interface class_students.Author
49、方法名:public <A extends annotation.Annotation> A[] getDeclaredAnnotationsByType( Class<A> annotationClass )
方法参数:Class<A> annotationClass
返回类型:A[]
方法说明:1、此类所有类型类注解都可以指定获取。
2、如果此类没有指定类型的类注解,则返回一个长度为0的数组。
3、如果此类有多个指定类型的类注解,则返回一个包含所有指定类型的类注解的数组。
举例:
class_students.Class_stuOutSon的类注解信息 :interface class_students.Author