1.运用
Class 类的实例表示正在运行的 Java 应用程序中的类和接口, 他是反射的基础入口
方法:得到字段属性对象Field,getFields(),
getDeclaredFields()
得到方法对象Method,
getMethods()
,getDeclaredMethods()
得到注解对象Annotation,
getAnnotations()
,getDeclaredAnnotations()。它们不同的是getDeclaredAnnotations得到的是当前成员所有的注解,不包括继承的。而 getAnnotations得到的是包括继承的所有注解
get****和getDeclared****的区别,前者是获得公共(public)的内容,包括继承父类的东西,后者获得的是所有修饰符的东西打不包括父类的
Field对象方法:
isAccessible() ,获取此对象的 accessible 标志的值。
setAccessible(boolean flag),值为 true 则指示反射的对象在使用时应该取消 Java 语言访问检查。值为 false 则指示反射的对象应该实施 Java 语言访问检查
isAnnotationPresent(Class<? extends Annotation> annotationClass),如果指定类型的注释存在于此元素上,则返回 true,否则返回 false
Method对象方法:最重要的invoke方法后面再仔细分析
2.应用