关于对象属性拷贝,虽说有现成的工具可用,之前都是自己写的反射进行拷贝,效率比较后,发现效率不高。
自从看了spring的源码,决定优化一下自定义的拷贝工具,主要是吸收spring的优秀思想,即使用内存作为缓存,同样的一个class拷贝时不用每次都进行反射,这样大大提升了效率。
话不多说,直接上源码:
class MethodObj{
private String name;
private Method readMethod;
private Method writeMethod;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Method getReadMethod() {
return readMethod;
}
public void setReadMethod(Method readMethod) {
this.readMethod = readMethod;
}
public Method getWriteMethod() {
return writeMethod;
}
public void setWriteMethod(Method writeMethod) {
this.writeMethod = writeMethod;
}
}
class CacheMethod{
Map<String, MethodObj> methodObjMap = new HashMap<>();
static Map<Class, CacheMethod> class


1771

被折叠的 条评论
为什么被折叠?



