You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/06/08 23:54:18 UTC
[jira] [Commented] (GROOVY-6744) Have the elvis operator (?:)
support the Optional type in Java 8
[ https://issues.apache.org/jira/browse/GROOVY-6744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16043661#comment-16043661 ]
Paul King commented on GROOVY-6744:
-----------------------------------
Marked as a breaking change for anyone relying on the old behavior.
> Have the elvis operator (?:) support the Optional type in Java 8
> ----------------------------------------------------------------
>
> Key: GROOVY-6744
> URL: https://issues.apache.org/jira/browse/GROOVY-6744
> Project: Groovy
> Issue Type: New Feature
> Components: Compiler
> Reporter: Aadi Deshpande
> Assignee: John Wagenleitner
> Labels: breaking
> Fix For: 2.5.0-beta-1
>
>
> With Java 8 and the rising popularity of Optional type in lieu of null management, it would be great if Groovy's elvis could handle Optional in the same way.
> {code:java}
> Optional<String> string1 = Optional.of("foo")
> Optional<String> string2 = Optional.empty()
> assert "foo" == ( string1 ?: "bar" )
> assert "bar" == ( string2 ?: "bar" )
> {code}
> Conversely, another option is to make elvis overloadable. ( something like {{orElse()}} ).
> That way, other Option/al types ( i.e. from Guava or FJ ) can have extension methods to support their use as well.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)