011--继续反射--加上代理
获取运行时 类 的 内部结构
--获取注解
getAnnotations()-返回数组
--获取修饰符
getModifiers()
--获取返回值类型
getReturnType().getName()
--获取参数类型
getParameterTypes()
Parameter
Parameter
Parameter
Parameter
--获取方法异常
getExceptionTypes
getExceptionTypes()
==获取运行时 类 的 构造器
getConstructors()
getConstructors()
==获取运行时 类的 父类
getGenericSuperclass()
getGenericSuperclass()
==获取运行时 类的 接口
getInferfaces()
getSuperclass().getInterfaces()
==获取运行时 类 所在的包
getPackage()
==注解
getAnnotations()
==调用运行时类的 属性 方法
获取指定的属性
getField(String name)
getDeclareField(String name)
非静态需要对象
clazz.newInstance()
属性.set(对象,值)
==调用运行时 类 的方法
getDeclaredMethod
参数1 方法名 参数2 参数类型
String.class
invoke()
==设置可用
setAccessible(true)
静态方法调用
传入对象 null
静态方法不需要对象调用
静态方法通过类调用
==调用运行时 类 的构造器
clazz.getDeclaredConstructor
指定参数列表
String.class
应为构造器名称 同 类名 无须传入
setAccessible(True)
确保可访问
constructor.newInstance()
========动态代理
一个类,只能有一个 public class
静态代理
编译阶段已经确认了

浙公网安备 33010602011771号