type
status
date
slug
summary
tags
category
icon
password
反射,允许运行时动态识别类相关的机制,一句话说通过生成的.class对象反向获取类对象信息的机制,装饰器模式

Type接口回顾

notion image
  • Class运行时Java的类和接口(枚举,注解)
  • GenericArrayType,包含ParameterizedType或者TypeVariable的数组元素
  • ParameterizedType表示参数化类型(Collection<String>)
  • TypeVariable,类型变量的父接(?,? extend,? super)
 

Reflector反射核心类

notion image
 

addDefaultConstructor

getClassMethods

addGetMethod

  • addMethodConflict
  • resolveGetterConflicts
  • addGetMethod
  • MethodInvoker
GetFeildInvoker和SetFeildInvoker分别对应读写操作
notion image
  • TypeParameterResolver
scansuperTYpes()过程
notion image
剩下的方法逻辑类似就不再列出。

ObjectFactory对象工厂

notion image
  • DefaultObjectFactory
主要功能是构造对象,各种重载的核心方法是instantiateClass
其中DefaultObjectFactory支持自定义,对应配置文件中的<ObjectFactory/>标签

Property对象属性操作工具包

  • PropertyCopier 属性复制
  • PropertyNamer 属性名称处理解析
  • PropertyTokenizer
用于直接读取属性,或者类似这样的结构获取

元对象MetaClass和MetaObject

MetaClas

MetaClass可以理解为一个涵盖所有Class信息的元对象

属性查找

  • hasGetter
  • geGetterType

MetaObject

Object的扩展包含对象装饰器以及对应工厂
  • forObject

对象包装器

notion image
BaseWrapper主要包含一些集合接口值的设置和获取,就不再贴出代码
  • BeanWrapper
MapWrapper和CollectionWrapper对应的是Map和集合相关的操作也不再贴出
  • SystemMetaObject

ExceptionUtil