You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ?: operator will return the right-hand-side value if the left-hand-side is null.
So we can write:
x.a.b.c ?: 'xxx'
This will return 'xxx' if x.a.b.c is null.
But if x.a.b or x.a or even x were null then we would get an error. If we want to cater for these possibly being null we have to write:
x?.a?.b?.c ?: 'xxx'
It would be nice if the ?: would return the right-hand-side value if either the left-hand-side evaluates to null or would throw a NullError if evaluated.
Then, x.a.b.c ?: 'xxx' would return 'xxx' if any of the dereferenced fields were null.
The text was updated successfully, but these errors were encountered:
The
?:
operator will return the right-hand-side value if the left-hand-side is null.So we can write:
This will return
'xxx'
ifx.a.b.c
is null.But if
x.a.b
orx.a
or evenx
were null then we would get an error. If we want to cater for these possibly being null we have to write:It would be nice if the
?:
would return the right-hand-side value if either the left-hand-side evaluates to null or would throw a NullError if evaluated.Then,
x.a.b.c ?: 'xxx'
would return'xxx'
if any of the dereferenced fields were null.The text was updated successfully, but these errors were encountered: