我写了以下代码
PodamFactory factory = new PodamFactoryImpl();
Honda honda1 = factory.manufacturePojo(Honda.class);
System.out.println(honda1.toString());
Honda honda2 = factory.manufacturePojoWithFullData(Honda.class);
System.out.println(honda2.toString());
这是Honda Class
public class Honda {
String name;
int version;
public Honda(String name, int version) {
this.name = name;
this.version = version;
}
...
}
我得到了
Honda{name='c00iZ2ponC', version=883048266}
Honda{name='c00iZ2ponC', version=883048266}
为什么podam每一代都会分配相同的值?
答案 0 :(得分:1)
这是因为所谓的memoization,它按类型缓存生成的对象。在PODAM的某些版本中默认启用此功能。
您可以通过以下方式禁用它
PodamFactory factory = new PodamFactoryImpl();
factory.getStrategy().setMemoizationEnabled(false);