hendrixjoseph commented on code in PR #933:
URL: https://github.com/apache/commons-lang/pull/933#discussion_r942883449


##########
src/main/java/org/apache/commons/lang3/ObjectUtils.java:
##########
@@ -1051,6 +1052,10 @@ public static boolean isEmpty(final Object object) {
         if (object instanceof Map<?, ?>) {
             return ((Map<?, ?>) object).isEmpty();
         }
+        if (object instanceof Optional<?>) {
+               return !((Optional<?>) object).isPresent();
+        }
+        

Review Comment:
   The optional would be non-empty. Take the following code snippet:
   ```java
   Optional<String> optional = Optional.of("");
   boolean empty = ObjectUtils.isEmpty(optional);
   // empty is false
   ```
   In the case of Optionals, we're concerned whether the optional is empty, not 
if the contents of the optional is empty.
   
   This is similar to having an array or collection of length 1 that only 
contains an empty string. In that case, ObjectUtils.isEmpty would still return 
false.
   
   I can update the JavaDoc to make it more clear.
   
   (And unrelated to this conversation, I notices I accidently slipped a couple 
tabs instead of spaces in. I'll fix that shortly.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to