Skip to content

Commit

Permalink
Simplify ObjectUtils#unwrapOptional
Browse files Browse the repository at this point in the history
This commit replaces optional.isEmpty() and optional.get() with
optional.orElse(null) for better efficiency and readability.

Closes gh-33612
  • Loading branch information
SungbinYang authored and sdeleuze committed Sep 30, 2024
1 parent 1c87e47 commit fc8bd64
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ public static boolean isEmpty(@Nullable Object obj) {
@Nullable
public static Object unwrapOptional(@Nullable Object obj) {
if (obj instanceof Optional<?> optional) {
if (optional.isEmpty()) {
return null;
}
Object result = optional.get();
Object result = optional.orElse(null);
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
return result;
}
Expand Down

0 comments on commit fc8bd64

Please sign in to comment.