1.优化of(T)方法, 让其等价于ofNullable(T);

This commit is contained in:
Zjp 2022-08-01 17:54:12 +08:00
parent f06162c1bd
commit 1bc419d72c

View File

@ -94,14 +94,14 @@ public class FastStream<T> implements Stream<T>, Iterable<T> {
} }
/** /**
* 返回包含单个元素的串行流 * 返回包含单个元素的串行流, 如果值为null, 则返回空的流, 不抛出异常
* *
* @param t 单个元素 * @param t 单个元素
* @param <T> 元素类型 * @param <T> 元素类型
* @return 包含单个元素的串行流 * @return 包含单个元素的串行流
*/ */
public static <T> FastStream<T> of(T t) { public static <T> FastStream<T> of(T t) {
return new FastStream<>(Stream.of(t)); return Opt.ofNullable(t).map(Stream::of).map(FastStream::new).orElseGet(FastStream::empty);
} }
/** /**