groovy - reference variable used in ternary conditional? (ex: var?this:null) -
is there way reference first part of ?: statement in groovy?
for example, there way shorten
def time = map.get('time') ? map.get('time').get('milliseconds') : null to like
def time = map.get('time') ? it.get('milliseconds') : null , "it" references first part of command?
it sounds want use safe navigation operator:
def time = map.get('time')?.get('milliseconds') if map.get('time') returns null reference, result of overall expression null, , get('milliseconds') won't called.
Comments
Post a Comment