Java BeanUtils - 在集合上运行

描述

Commons-Collections基于接口,实现和实用程序构建.它包含代码中的Closure接口,可以应用于任意输入对象,代码允许将Closures应用于集合的内容. Closure被称为 BeanPropertyValueChangeClosure 将指定的属性设置为指定的值.此值可以与commons-collections结合使用,其中所有bean都将指定的属性指定给集合中的指定值.

例如,您可以将myCar属性设置为整个集合为TRUE,如下所示:

 
//创建闭包
 BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("myCar" ",Boolean.TRUE); 
//更新Collection 
 CollectionUtils.forAllDo(myCollection,closure);