[
https://issues.apache.org/jira/browse/GROOVY-1733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-1733:
------------------------------
Fix Version/s: (was: 3.0.0-alpha-1)
> Let boolean operators (||, &&) evaluate to the value instead of the boolean
> equivalent
> --------------------------------------------------------------------------------------
>
> Key: GROOVY-1733
> URL: https://issues.apache.org/jira/browse/GROOVY-1733
> Project: Groovy
> Issue Type: Improvement
> Components: syntax
> Reporter: Siegfried Puchbauer
> Assignee: Guillaume Delcroix
> Priority: Minor
>
> It would enable you to do some things a lot faster (eg. variable declaration)
> and would improve the current null-save navigation
> examples:
> {code:java}
> def a = 0
> def b = null
> def c = "a string"
> def d = ""
> def val = a || c // c gets evalutated, because the boolean equivalent of a
> (0) is false
> assert a || b == null
> assert c || d == "a string"
> assert d || a == 0
> assert a || "another string" == "a string"
> assert d || "another string" == "another string"
> {code}
> for null-save navigation:
> {code:java}
> def val = aMap?.aProperty?.aSubProperty || "a default Value"
> {code}
> or even for causal execution of code
> {code:java}
> myobject.aMethodThatReturnsNullWhenItFails() || myobject.anotherMethod()
> // myobject.anotherMethod gets only executed the result of the first call
> evalutes to false
> {code}
> The current notation would not be affected in a negative way
> {code:java}
> if(a || b){...} // would still work
> {code}
> you would still have the possibility to get the boolean value by using !!
> eg.
> {code:java}
> assert (0 || 15) instanceof Integer
> assert !!(0 || 15) instanceof Boolean
> {code}
> The only language I know, which supports this currently is JavaScript
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)