mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
Merge pull request #2865 from mcp2016/针对coll1为只读集合的补偿
针对CollUtil.subtract coll1 为只读集合的补偿
This commit is contained in:
commit
36816bac59
@ -365,11 +365,18 @@ public class CollUtil {
|
|||||||
*/
|
*/
|
||||||
public static <T> Collection<T> subtract(Collection<T> coll1, Collection<T> coll2) {
|
public static <T> Collection<T> subtract(Collection<T> coll1, Collection<T> coll2) {
|
||||||
Collection<T> result = ObjectUtil.clone(coll1);
|
Collection<T> result = ObjectUtil.clone(coll1);
|
||||||
if (null == result) {
|
try {
|
||||||
result = CollUtil.create(coll1.getClass());
|
if (null == result) {
|
||||||
|
result = CollUtil.create(coll1.getClass());
|
||||||
|
result.addAll(coll1);
|
||||||
|
}
|
||||||
|
result.removeAll(coll2);
|
||||||
|
} catch (UnsupportedOperationException e){
|
||||||
|
// 针对 coll1 为只读集合的补偿
|
||||||
|
result = CollUtil.create(AbstractCollection.class);
|
||||||
result.addAll(coll1);
|
result.addAll(coll1);
|
||||||
|
result.removeAll(coll2);
|
||||||
}
|
}
|
||||||
result.removeAll(coll2);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user