groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mauro Molinari <mauro...@tiscali.it>
Subject Re: [PROPOSAL]new operator ?=
Date Wed, 23 Nov 2016 08:26:43 GMT
In my humble personal experience, I confirm I would have find it useful 
when properties are involved, i.e.:

foo.property ?= 'defaultValue'
instead of
foo.property = foo.property?: 'defaultValue'
or the lengthy:
def a = foo.property
foo.property = a?: 'defaultValue'

Not to say in case of nested properties:
foo.bar.baz.property = foo.bar.baz.property?: 'defaultValue'

Mauro

Il 23/11/2016 09:15, C├ędric Champeau ha scritto:
> I would say +1 to ?= . There are a few cases where I would have used 
> it. Typically, configuring some defaults after the fact. I'm not 
> saying this is a good pattern in general, but it can come handy:
>
> void finalize(Config config) {
>    config.with {
>       foo ?= 'foo'
>       bar ?= 'bar'
>       baz ?= 'baz'
>    }
> }


Mime
View raw message