For further consideration...

Reinier Zwitserloot reinier at zwitserloot.com
Wed Mar 25 10:04:08 PDT 2009


Excellent point about the disconnection between x?[0] where x is null  
and x is the empty array. I agree: That shouldn't be in the elvis  
operators proposal.

Arrays aren't nearly as common as member access anyway.

  --Reinier Zwitserloot



On Mar 25, 2009, at 17:44, Tim Keith wrote:

> I would like to suggest at least leaving out ?[]
>
> The example in the proposal is not very compelling:
>    class Group {
>        Person[] members; // null if no members
>    }
>    class Person {
>        String name; // may be null
>    }
>    final String aMember = g?.members?[0]?.name ?: "nobody";
>
> If members is null you get "nobody" but if members is empty (the  
> logical way
> to signify "no members") you get ArrayIndexOutOfBoundsException.
>
> "array?[...]" is like saying: if array is null treat it like it's an
> infinitely
> long array of nulls.
>
> "object?.member" is like saying: if object it null, treat it like  
> every
> field
> is null and every method returns null.
> The array analog to that should be that "array?.length" means
>    array == null ? 0 : array.length
>
> -- Tim
>
> On Tue, Mar 24, 2009 at 4:18 PM, Joseph D. Darcy <Joe.Darcy at sun.com>  
> wrote:
>
>> Jeremy Manson wrote:
>>> Joe,
>>>
>>> Is it all the Elvis operators, or just ?: ?
>>>
>>
>> The more modest version is more likely to get in.
>>
>> -Joe
>>
>>
>>
>




More information about the coin-dev mailing list