I think I misunderstood.
The correct alternative is something like
if (someValue != null) speed = someValue
speed = someValue ?: speed
Just like my original reply, I think most people would assume
speed ?= someVlue to perform just like the Ruby
a ||= b (if left side is null, assign some value).
I think this would have limited gain.
speed ?= someValue
is only short for
if (speed == null) speed = someValue
speed = speed ?: someValue
speed ?= someValue is slightly shorter than the current options, the current options work fine as they are now.
All of these options assume we’re working with non-final fields. Maybe I’m missing some use case where you have a ton of
null properties that need to be set to default values.