加载类: Class.forName()
解剖类: getXXX()
Constructor 构造方法
getConstructor()
getDeclaredConstructor()
newInstance()
setAccessible() //暴力反射
Method 方法
getMethod()
getDeclaredMethod
invoke()
setAccessible()
Field 字段
getField
getDeclaredField()
setAccessible()
get()
字段中含有getXXX()或setXXX()方法的可称属性
内省introspector
内省(Introspector) 是Java 语言对 JavaBean 类属性、事件的一种缺省处理方法。
PropertyDescriptor类:
PropertyDescriptor类表示JavaBean类通过存储器导出一个属性。主要方法:
1. getPropertyType(),获得属性的Class对象;
2. getReadMethod(),获得用于读取属性值的方法;getWriteMethod(),获得用于写入属性值的方法;
3. hashCode(),获取对象的哈希值;
4. setReadMethod(Method readMethod),设置用于读取属性值的方法;
5. setWriteMethod(Method writeMethod),设置用于写入属性值的方法。
Introspector类:
将JavaBean中的属性封装起来进行操作。
在程序把一个类当做JavaBean来看,就是调用Introspector.getBeanInfo()方法,得到的BeanInfo对象封装了把这个类当做JavaBean看的结果信息,即属性的信息。
getPropertyDescriptors(),获得属性的描述,可以采用遍历BeanInfo的方法,来查找、设置类的属性。
通过这两个类的比较可以看出,都是需要获得PropertyDescriptor,只是方式不一样:前者通过创建对象直接获得,后者需要遍历,所以使用PropertyDescriptor类更加方便。
BeanUtils工具包(前面有提到)