优化代码

dev
ZhouXY108 2024-10-14 16:35:19 +08:00
parent 1b0cf2bd42
commit 1ade08783f
1 changed files with 3 additions and 3 deletions

View File

@ -64,7 +64,7 @@ public class OptionalTools {
* @return {@link OptionalInt}
*/
public static OptionalInt toOptionalInt(Optional<Integer> 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<Long> 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<Double> optionalObj) {
return optionalOf(optionalObj.orElse(null));
return optionalObj.isPresent() ? OptionalDouble.of(optionalObj.get()) : OptionalDouble.empty();
}
/**