Java Beanutils 简明教程
Java BeanUtils - Operating On Collections
Description
Commons-Collections 建立在接口、实现和工具之上。它在代码中包含了一个 Closure 接口,该接口可以应用于任意输入对象的代码允许将 Closure 应用于集合的内容。有一个 Closure 称为 BeanPropertyValueChangeClosure,它将指定的属性设置为指定的值。此值可以与 commons-collections 相结合,其中所有 Bean 将指定的属性在集合中设置为指定的值。
例如,您可以将 myCar 属性设置为 TRUE,如下所示:
//creating the closure
BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure( "myCar", Boolean.TRUE );
//updating the Collection
CollectionUtils.forAllDo( myCollection, closure );