Case in point, Java expert Trisha Gee at JBCNConf’18:
if (customer?.name?.startsWith("A") == true) { ... }
Then I can use this question mark to basically chain my way through
customer
,name
,startsWith
, and if there’snull
anywhere there it would just ignore it […] and won’t follow the chain through.
In the context of this discussion, yes: this is how we want to understand ?
but it’s a little more subtle than that – in fact, it does follow the chain through! I think the point we’re trying to make above is that the subtlety is surprising.
There’s also the issue I laid out in Is the idiom for checking nullable booleans helpful? in this snippet.