Skip to content

Commit fc8bd64

Browse files
SungbinYangsdeleuze
authored andcommitted
Simplify ObjectUtils#unwrapOptional
This commit replaces optional.isEmpty() and optional.get() with optional.orElse(null) for better efficiency and readability. Closes gh-33612
1 parent 1c87e47 commit fc8bd64

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

spring-core/src/main/java/org/springframework/util/ObjectUtils.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ public static boolean isEmpty(@Nullable Object obj) {
173173
@Nullable
174174
public static Object unwrapOptional(@Nullable Object obj) {
175175
if (obj instanceof Optional<?> optional) {
176-
if (optional.isEmpty()) {
177-
return null;
178-
}
179-
Object result = optional.get();
176+
Object result = optional.orElse(null);
180177
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
181178
return result;
182179
}

0 commit comments

Comments
 (0)