[ 
https://issues.apache.org/jira/browse/GROOVY-7611?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15443978#comment-15443978
 ] 

ASF GitHub Bot commented on GROOVY-7611:
----------------------------------------

Github user blackdrag commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/403#discussion_r76537642
  
    --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java ---
    @@ -10563,13 +10563,21 @@ private void prepare() {
         /**
          * Coerce an object instance to a boolean value.
          * An object is coerced to true if it's not null, to false if it is 
null.
    +     * One exception to this is in the case of a non-null {@code 
java.util.Optional}
    +     * in which case the result of the {@code isPresent} method is 
returned.
          *
          * @param object the object to coerce
          * @return the boolean value
          * @since 1.7.0
          */
         public static boolean asBoolean(Object object) {
    -        return object != null;
    +        if (object == null) {
    +            return false;
    +        }
    +        if ("java.util.Optional".equals(object.getClass().getName())) {
    --- End diff --
    
    just a very small thing.. could you add a todo to move this into a jvm8 
module once we decided to make that our minimum jdk for the build?


> java.util.Optional should evaluate to false if empty
> ----------------------------------------------------
>
>                 Key: GROOVY-7611
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7611
>             Project: Groovy
>          Issue Type: Improvement
>    Affects Versions: 2.4.5
>            Reporter: Christopher Smith
>            Priority: Minor
>
> In the spirit of the rest of the Groovy truth semantics, I suggest that an 
> empty {{java.util.Optional}}, which is essentially a stream-safe equivalent 
> of {{null}}, should evaluate to false: {{asBoolean()}} should simply delegate 
> to {{isPresent()}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to