Merge pull request #2865 from mcp2016/针对coll1为只读集合的补偿

针对CollUtil.subtract coll1 为只读集合的补偿
This commit is contained in:
Golden Looly 2023-01-19 11:37:37 +08:00 committed by GitHub
commit 36816bac59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -365,11 +365,18 @@ public class CollUtil {
*/
public static <T> Collection<T> subtract(Collection<T> coll1, Collection<T> coll2) {
Collection<T> result = ObjectUtil.clone(coll1);
if (null == result) {
result = CollUtil.create(coll1.getClass());
try {
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.removeAll(coll2);
}
result.removeAll(coll2);
return result;
}