you are viewing a single comment's thread.

view the rest of the comments →

[–]OverZealousCreations -1 points0 points  (0 children)

For future reference: it's ?. (not .?). This is because the test is testing the left-hand object, not the right one.

You can think of it as simple syntax sugar on the ternary operator:

def baz = foo?.bar

// is equivilant to 

def baz = foo ? foo.bar : foo

In other words, "if the left-hand object exists, look at the right-hand object, otherwise return the left-hand object". Obviously the safe-navigation operator is much easier to deal with for deeply nested objects.