GROOVY-5306 (?= operator)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

GROOVY-5306 (?= operator)

eric.milles

GROOVY-5306 (https://issues.apache.org/jira/browse/GROOVY-5306) states:

 

Add "a ?= 2" support: should be expanded to "a = a == null ? 2 : a"

 

Shouldn't the expansion be "a = (a != null ? a : 2)"?  Like other ternary situations, the alternative would not be evaluated unless needed.  Also, is it a null check and not Groovy truth in the condition?

 

If "a" is not null in this example, does the bytecode actually execute an assignment?  That seems unnecessary as well.