Proposal: Elvis and Other Null-Safe Operators
neal at gafter.com
Sun Apr 5 07:11:33 PDT 2009
On Sun, Apr 5, 2009 at 4:40 AM, Mark Mahieu <markmahieu at googlemail.com> wrote:
>> List list = null;
>> boolean b = list?.isEmpty() ?: true;
> I don't understand how that combination is supposed to work, given
> this part of the proposal:
> "A null-safe method invocation expression e1?.name(args) ... the type
> of the result is the same as the type of e1.name(args). It is an
> error if this is not a reference type."
> Doesn't that mean that the compiler should reject the expression
> 'list?.isEmpty()' ?
Given the spec as written, yes. However, it could be changed so that
the result is the same as the result of the rewriting in the
"compilation" section of the spec. In that case its result would be
Boolean. However, that is likely to result in more runtime null
errors, not fewer, if people do things like
if (list?.isEmpty()) ...
More information about the coin-dev