public class ReflectionBuilder extends Object implements Builder<DifferentResult>
Differentable.diff(Object)方法.
使用反射发现要差异的对象的所有非静态、非瞬态字段(包括继承字段),并比较它们之间的差异.
public class Person implements Diffable<Person> {
String name;
int age;
boolean smoker;
...
public DiffResult diff(Person obj) {
return new ReflectionDiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
.build();
}
}
传递给构造函数的ToStringStyle嵌入到返回的DiffResult中,
并影响DiffResult. tostring()方法的风格。可以通过调用
DifferentResult.toString(ToStringStyle)覆盖此样式选择.
Builder.HashKey| Constructor and Description |
|---|
ReflectionBuilder(T lhs,
T rhs,
ToStringStyle style)
使用指定样式为指定对象构造一个生成器
|
public ReflectionBuilder(T lhs,
T rhs,
ToStringStyle style)
如果lhs == rhs或lhs.equals(rhs),
则构建器将不计算对append(…)的任何调用,
并在build()执行时返回一个空的DifferentResult.
T - 要区分的对象的类型lhs - this 对象rhs - 反对的对象style - 当输出对象时将使用该样式,null使用默认值public DifferentResult build()
Builderbuild in interface Builder<DifferentResult>Copyright © 2020. All rights reserved.