Proposal: Elvis and Other Null-Safe Operators
Stephen Colebourne
jodastephen at gmail.com
Thu Mar 19 10:18:32 PDT 2009
Neal Gafter wrote:
> On Thu, Mar 19, 2009 at 1:26 AM, Jacek Kolodziejczyk
> <jacek.p.kolodziejczyk at gmail.com> wrote:
>
>> In my opinion the most obtrusive part in the current state of proposals
>> is assumption that the invocation on null object should always return null.
>> If I understand it correctly the following would break at runtime,
>> because null cannot be assigned to boolean:
>>
>> List list = null;
>> boolean b = list?.isEmpty();
>>
>
> That would be a compile-time error because of the incompatibility
> between null and boolean.
>
The intention is that you can write a combination to handle this with
the submitted Coin proposal:
List list = null;
boolean b = list?.isEmpty() ?: true;
Stephen
More information about the coin-dev
mailing list