diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/OptionalTools.java b/src/main/java/xyz/zhouxy/plusone/commons/util/OptionalTools.java index b24787f..288ac77 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/OptionalTools.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/OptionalTools.java @@ -64,7 +64,7 @@ public class OptionalTools { * @return {@link OptionalInt} 实例 */ public static OptionalInt toOptionalInt(Optional optionalObj) { - return optionalOf(optionalObj.orElse(null)); + return optionalObj.isPresent() ? OptionalInt.of(optionalObj.get()) : OptionalInt.empty(); } /** @@ -91,7 +91,7 @@ public class OptionalTools { * @return {@link OptionalLong} 实例 */ public static OptionalLong toOptionalLong(Optional optionalObj) { - return optionalOf(optionalObj.orElse(null)); + return optionalObj.isPresent() ? OptionalLong.of(optionalObj.get()) : OptionalLong.empty(); } /** @@ -118,7 +118,7 @@ public class OptionalTools { * @return {@link OptionalDouble} 实例 */ public static OptionalDouble toOptionalDouble(Optional optionalObj) { - return optionalOf(optionalObj.orElse(null)); + return optionalObj.isPresent() ? OptionalDouble.of(optionalObj.get()) : OptionalDouble.empty(); } /**