!580 Opt.ofEmptyAble从List拓展为Collection

Merge pull request !580 from 阿超/v5-dev
This commit is contained in:
Looly 2022-03-21 14:21:01 +00:00 committed by Gitee
commit 82ab60f046
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -29,7 +29,7 @@ import cn.hutool.core.lang.func.Func0;
import cn.hutool.core.lang.func.VoidFunc0;
import cn.hutool.core.util.StrUtil;
import java.util.List;
import java.util.Collection;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
@ -108,7 +108,7 @@ public class Opt<T> {
* @return 一个包裹里元素可能为空的 {@code Opt}
* @since 5.7.17
*/
public static <T> Opt<List<T>> ofEmptyAble(List<T> value) {
public static <T, R extends Collection<T>> Opt<R> ofEmptyAble(R value) {
return CollectionUtil.isEmpty(value) ? empty() : new Opt<>(value);
}