Simplify ObjectUtils#unwrapOptional
This commit replaces optional.isEmpty() and optional.get() with optional.orElse(null) for better efficiency and readability. Closes gh-33612
This commit is contained in:
committed by
Sébastien Deleuze
parent
1c87e4795d
commit
fc8bd64f34
@@ -173,10 +173,7 @@ public abstract class ObjectUtils {
|
||||
@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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user