To quote an old and related thread:
Perhaps we ought to have an unboxed Option
in the stdlib to avoid allocation costs over using null
, but I agree that we should NOT encourage the use of null
by adding such an operator. However, it might be worth adding such an operator for Option
or an unboxed version of Option
.
Additionally, I think it’s worth noting that the elvis operator with null
is a bit inconsistent as well. When being used with null
, it doesn’t distinguish between its RHS being nullable or not—that is, it represents the operations equivalent to both orElse
and getOrElse
on Option
. I think that it is both trivial and valuable to separate those two cases into different symbols (e.g. :?
and one of ::?
or :??
)