```
feat(stream): 优化 SuperStream 的 toArray 方法实现- 调整 toArray 方法,支持传入 Class 参数以正确创建泛型数组 - 原无参 toArray 方法改为返回 Object[],避免类型转换异常 - 移除对 ForEach 工具类的依赖 - 提升流处理中数组转换的灵活性与安全性 ``` ``` feat(collection): 改进 toArray 工具方法支持泛型数组创建 - 新增基于 reified 泛型的 toArray 扩展方法,自动推断数组类型 - 添加带 Class 参数的 toArray 重载方法,用于明确指定元素类型 - 处理空列表时直接返回空数组,避免后续操作异常 ``` ``` build(gradle): 升级 dokka 插件版本并更新项目依赖- 将 org.jetbrains.dokka 插件升级至 2.1.0-Beta 版本 - 添加 jna5.17.0 依赖用于本地库调用支持 - 引入 mybatis-plus-core 3.0.1 编译依赖 - 更新项目版本号从 4.1.7 至 4.1.8 ```
This commit is contained in:
@@ -16,14 +16,13 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile SuperStream.java
|
||||
* LastUpdate 2025-09-20 13:24:35
|
||||
* LastUpdate 2025-09-21 14:22:13
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.stream;
|
||||
|
||||
import com.mingliqiye.utils.collection.Collections;
|
||||
import com.mingliqiye.utils.foreach.ForEach;
|
||||
import com.mingliqiye.utils.functions.P1Function;
|
||||
import com.mingliqiye.utils.functions.P2Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -887,16 +886,13 @@ public class SuperStream<T> implements Stream<T> {
|
||||
*/
|
||||
@NotNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public T[] toArray() {
|
||||
List<T> list = toAList();
|
||||
if (list.isEmpty()) {
|
||||
throw new StreamEmptyException("Stream is empty");
|
||||
}
|
||||
T[] items = (T[]) Array.newInstance(list.get(0).getClass(), list.size());
|
||||
ForEach.forEach(list, (v, i) -> {
|
||||
items[i] = v;
|
||||
});
|
||||
return items;
|
||||
public T[] toArray(Class<T> clazz) {
|
||||
return stream.toArray(i -> (T[]) Array.newInstance(clazz, i));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Object[] toArray() {
|
||||
return stream.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user