groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-7611) java.util.Optional should evaluate to false if empty
Date Fri, 09 Jun 2017 00:10:18 GMT

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

Paul King edited comment on GROOVY-7611 at 6/9/17 12:09 AM:
------------------------------------------------------------

Marked as a breaking change for anyone relying on the old behavior.

If you were working around the old behavior by using this long-hand form, i.e.:
{code}
def empty = Optional.empty()
def foo = Optional.of('foo')
assert foo.isPresent() ? 1 : -1 == 1
assert empty.isPresent() ? 1 : -1 == -1
{code}
you can leave the code as is or change it to the shorter equivalent:
{code}
assert foo ? 1 : -1 == 1
assert empty ? 1 : -1 == -1
{code}


was (Author: paulk):
Marked as a breaking change for anyone relying on the old behavior.

> 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
>            Assignee: John Wagenleitner
>            Priority: Minor
>              Labels: breaking
>             Fix For: 2.5.0-beta-1
>
>
> 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.15#6346)

Mime
View raw message