For further consideration... (original) (raw)

Tim Keith tim.keith at gmail.com
Wed Mar 25 09:44:50 PDT 2009


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