diff --git a/hutool-core/src/main/java/cn/hutool/core/lang/Opt.java b/hutool-core/src/main/java/cn/hutool/core/lang/Opt.java index cebf71961..9f3dac1da 100644 --- a/hutool-core/src/main/java/cn/hutool/core/lang/Opt.java +++ b/hutool-core/src/main/java/cn/hutool/core/lang/Opt.java @@ -246,12 +246,14 @@ public class Opt { * 如果包裹里元素的值存在,就执行对应的操作,并返回本身 * 如果不存在,返回一个空的{@code Opt} * + *

属于 {@link #ifPresent}的链式拓展 + * * @param action 值存在时执行的操作 + * @return this * @throws NullPointerException 如果值存在,并且传入的操作为 {@code null} - * @apiNote 属于 {@link #ifPresent}的链式拓展 * @author VampireAchao */ - public Opt peek(Consumer action) { + public Opt peek(Consumer action) throws NullPointerException { Objects.requireNonNull(action); if (isEmpty()) { return Opt.empty();