Details
Description
It would enable you to do some things a lot faster (eg. variable declaration) and would improve the current null-save navigation
examples:
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"
for null-save navigation:
def val = aMap?.aProperty?.aSubProperty || "a default Value"
or even for causal execution of code
myobject.aMethodThatReturnsNullWhenItFails() || myobject.anotherMethod()
// myobject.anotherMethod gets only executed the result of the first call evalutes to false
The current notation would not be affected in a negative way
if(a || b){...} // would still work
you would still have the possibility to get the boolean value by using !!
eg.
assert (0 || 15) instanceof Integer assert !!(0 || 15) instanceof Boolean
The only language I know, which supports this currently is JavaScript
Activity
blackdrag blackdrag
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 2.0 [ 13489 ] |
Guillaume Laforge
made changes -
| Status | Open [ 1 ] | Closed [ 6 ] |
| Assignee | Guillaume Laforge [ guillaume ] | |
| Resolution | Won't Fix [ 2 ] |