fix 修复 StreamUtils 返回不可变类型报错问题

This commit is contained in:
疯狂的狮子Li
2025-09-02 15:51:42 +08:00
parent f4cfd1c913
commit 5a43212ccc

View File

@ -27,7 +27,7 @@ public class StreamUtils {
*/ */
public static <E> List<E> filter(Collection<E> collection, Predicate<E> function) { public static <E> List<E> filter(Collection<E> collection, Predicate<E> function) {
if (CollUtil.isEmpty(collection)) { if (CollUtil.isEmpty(collection)) {
return Collections.emptyList(); return CollUtil.newArrayList();
} }
return collection.stream() return collection.stream()
.filter(function) .filter(function)
@ -127,7 +127,7 @@ public class StreamUtils {
*/ */
public static <E> List<E> sorted(Collection<E> collection, Comparator<E> comparing) { public static <E> List<E> sorted(Collection<E> collection, Comparator<E> comparing) {
if (CollUtil.isEmpty(collection)) { if (CollUtil.isEmpty(collection)) {
return Collections.emptyList(); return CollUtil.newArrayList();
} }
return collection.stream() return collection.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
@ -265,7 +265,7 @@ public class StreamUtils {
*/ */
public static <E, T> List<T> toList(Collection<E> collection, Function<E, T> function) { public static <E, T> List<T> toList(Collection<E> collection, Function<E, T> function) {
if (CollUtil.isEmpty(collection)) { if (CollUtil.isEmpty(collection)) {
return Collections.emptyList(); return CollUtil.newArrayList();
} }
return collection.stream() return collection.stream()
.map(function) .map(function)