单元测试:使用Junit单元测试框架


使用Junit单元测试:




通过左侧的对❌来进行提示
Junit框架的常见注解:




反射(用于框架,也是最重要):展示框架的成员信息
由于是用于对象,即使在获取之后也是需要传入获取类型的对象,调用的该类型对象的功能。
此处类型指下面的获取的:类...
反射:Java 反射(Reflection) - Java教程 - 菜鸟教程
public void setAccessible(boolean flag) 设置为true,表示禁止检查访问控制( 暴力反射)
获取任何成员等后都可以将其对象放入该暴力反射中,之后可以访问私有的类型。


反射第一步获取类的对象:
三种获取的都是一种效果。


获取类的构造器:是可以获取私有构造器后,使用构造器对象来访问私有构造器,来创建对象的。



需要对应构造器的形参

即在获取构造器后,通过构造器对象的newInstance创建一个对象,如果有参数的时候许哟啊传入参数。
由于获取构造器创建对象时默认是object类型的需要进行强转,或者在获取构造器的时候声明一个泛型。(一般进行强转)
暴力反射用于获取私有构造器对象后,通过构造器对象来调用私有的构造器。
(需要先进行暴力反射在使用构造器对象创建)

获取类的成员变量:


void set(Object obj, object value): 赋值 obj表示对象,value表示要赋予的值。
object get(Object obj) 取值
public void setAccessible(boolean flag) 设置为true,表示禁止检查访问控制( 暴力反射)
获取类中的方法:


反射的简单应用:




关键在于要暴力反射确保数据都能够被获取。
注解(用于框架功能):
基本上每个地方都可以进行使用
深入注解请移步。




元注解(修饰注解的注解):



test元注解的内部。
注解的解析(输出注解的内容(对象/方法/...)):

示例:解析对象的属性


模拟简易版Junit框架:



动态代理:相当于python的修饰器
将对象的一部分需要的,转移到别的地方进行处理


实际上代理只是处理冗杂的事情,主要的还是由对象自己进行处理。
动态代理的实例:





使用代理进行:


