代码拉取完成,页面将自动刷新
调用clear报错,传入对象是List类型.
/**
* 过滤<br>
* 过滤过程通过传入的Editor实现来返回需要的元素内容,这个Editor实现可以实现以下功能:
*
* <pre>
* 1、过滤出需要的对象,如果返回null表示这个元素对象抛弃
* 2、修改元素对象,返回集合中为修改后的对象
* </pre>
*
* @param <T> 集合元素类型
* @param collection 集合
* @param editor 编辑器接口
* @return 过滤后的数组
*/
public static <T> Collection<T> filter(Collection<T> collection, Editor<T> editor) {
Collection<T> collection2 = ObjectUtil.clone(collection);
collection2.clear();
T modified;
for (T t : collection) {
modified = editor.edit(t);
if (null != modified) {
collection2.add(t);
}
}
return collection2;
}
jdk8 源码注释!
/**
* Removes all of the elements from this collection (optional operation).
* The collection will be empty after this method returns.
*
* @throws UnsupportedOperationException if the <tt>clear</tt> operation
* is not supported by this collection
*/
void clear();
java.util.Collection#clear
我这边测试没有问题:
ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
Collection<String> filtered = CollUtil.filter(list, new Editor<String>() {
@Override
public String edit(String t) {
return t +1;
}});
Console.log(filtered);
看样子你传入的List很有可能是个UnmodifiedList,这种不可变的List并不支持此方法。后续版本会改进这里。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
受教了,谢谢!
Java集合操作asList方法产生的List对象不可改变
登录 后才可以发表评论