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 falseassert a || b == nullassert 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 !!
The only language I know, which supports this currently is JavaScript
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 falseassert a || b == nullassert 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.